#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
unsigned int checkUser(char *login) {
  char line[80];
  FILE *passwdfile = NULL;
  passwdfile = fopen("/etc/passwd", "r");
  if (passwdfile != NULL) {
    while (fgets(line, 80, passwdfile) != NULL) {
      if ((strstr(line, login)) != NULL)
        return 1;
    }
    fclose(passwdfile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkUser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x68(%rbp)
lea    0xea5(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     11c8 <checkUser+0x88>
jmp    117b <checkUser+0x3b>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11bf <checkUser+0x7f>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11ba <checkUser+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    11cf <checkUser+0x8f>
jmp    117b <checkUser+0x3b>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkUser>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r15
lea    0xeac(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11a5 <checkUser+0x65>
mov    %rax,%rbp
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     119d <checkUser+0x5d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1170 <checkUser+0x30>
mov    $0x1,%r14d
jmp    11a5 <checkUser+0x65>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkUser(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [80 x i8]
%5 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %25
9: ; preds = %1
br label %10
10: ; preds = %21, %9
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i32* @fgets(i8* %11, i32 80, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32* @strstr(i8* %16, i8* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %2
br label %26
21: ; preds = %15
br label %10
22: ; preds = %10
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkUser(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1, %9
%7 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = call i32* @strstr(i8* %3, i8* dereferenceable(1) %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %6, label %14
12: ; preds = %6
%13 = call i32 @fclose(i32* %4)
br label %14
14: ; preds = %9, %1, %12
%15 = phi i32 [ 0, %12 ], [ 0, %1 ], [ 1, %9 ]
ret i32 %15
}