#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ eout(char *, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(scalar_t__);
int strlen(char *);
int find_user_in_file(char *file, char *u) {
  FILE *fp;
  char buf[100];
  fp = fopen(file, "r");
  if (fp == NULL) {
    if (errno != ENOENT)
      eout("can't open '%s' for reading: %s\n", file, strerror(errno));
    return -1;
  }
  while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
    int l = strlen(buf);
    if (l > 0 && buf[l - 1] == '\n') {
      buf[l - 1] = '\0';
      if (strcmp(buf, u) == 0) {
        fclose(fp);
        return 1;
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<find_user_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f7 <find_user_in_file+0x87>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     11eb <find_user_in_file+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
lea    0xe1c(%rip),%rdi
call   1080 <eout@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <find_user_in_file+0x142>
jmp    11fc <find_user_in_file+0x8c>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x63,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12a2 <find_user_in_file+0x132>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jle    129d <find_user_in_file+0x12d>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    129d <find_user_in_file+0x12d>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1298 <find_user_in_file+0x128>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <find_user_in_file+0x142>
jmp    129d <find_user_in_file+0x12d>
jmp    11fc <find_user_in_file+0x8c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_user_in_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1209 <find_user_in_file+0x99>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x63,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <find_user_in_file+0x8d>
mov    %rsp,%rbx
jmp    11c5 <find_user_in_file+0x55>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x63,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <find_user_in_file+0x8d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11b0 <find_user_in_file+0x40>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    11b0 <find_user_in_file+0x40>
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b0 <find_user_in_file+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
jmp    123a <find_user_in_file+0xca>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    123a <find_user_in_file+0xca>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdi
mov    0x2db6(%rip),%rax
mov    $0xffffffff,%ebp
cmp    (%rax),%rdi
je     123a <find_user_in_file+0xca>
call   1090 <strerror@plt>
lea    0xdd2(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <eout@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [33 x i8] c"can't open '%s' for reading: %s\0A\00"
define i32 @find_user_in_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i64, i64* @errno
%20 = call i32 @strerror(i64 %19)
%21 = call i32 @eout(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %20)
br label %22
22: ; preds = %17, %13
store i32 -1, i32* %3
br label %59
23: ; preds = %2
br label %24
24: ; preds = %55, %23
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 99, i32* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %56
29: ; preds = %24
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %29
%35 = load i32, i32* %8
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %55
42: ; preds = %34
%43 = load i32, i32* %8
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%48 = load i8*, i8** %5
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
store i32 1, i32* %3
br label %59
54: ; preds = %42
br label %55
55: ; preds = %54, %34, %29
br label %24
56: ; preds = %24
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %3
br label %59
59: ; preds = %56, %51, %22
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [33 x i8] c"can't open '%s' for reading: %s\0A\00"
define i32 @find_user_in_file(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 99, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %34, label %17
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %36, label %14
14: ; preds = %10
%15 = tail call i32 @strerror(i64 %11)
%16 = tail call i32 @eout(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %15)
br label %36
17: ; preds = %7, %31
%18 = call i32 @strlen(i8* %4)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = add nsw i32 %18, -1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %20
store i8 0, i8* %23
%27 = call i64 @strcmp(i8* %4, i8* %1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @fclose(i32* %5)
br label %36
31: ; preds = %17, %20, %26
%32 = call i32* @fgets(i8* %4, i32 99, i32* %5)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %17
34: ; preds = %31, %7
%35 = call i32 @fclose(i32* %5)
br label %36
36: ; preds = %29, %10, %14, %34
%37 = phi i32 [ 0, %34 ], [ -1, %14 ], [ -1, %10 ], [ 1, %29 ]
ret i32 %37
}