#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
int check_for_user(FILE *fp, const char *name) {
  char *buffer;
  size_t len;
  int found = 0;
  len = strlen(name);
  if ((buffer = malloc(len + 2)) == NULL)
    errx(EXIT_FAILURE, "virtual memory exhausted");
  while (fgets(buffer, len + 2, fp) != NULL) {
    if ((strncmp(name, buffer, len) == 0) && (buffer[len] == '\n')) {
      found = 1;
      break;
    }
  }
  fclose(fp);
  free(buffer);
  return found;
}


x86 assembly (clang, -O0):
<check_for_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c4 <check_for_user+0x54>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <errx@plt>
jmp    11c9 <check_for_user+0x59>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x2,%rsi
mov    -0x8(%rbp),%rdx
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1229 <check_for_user+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1224 <check_for_user+0xb4>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1224 <check_for_user+0xb4>
movl   $0x1,-0x24(%rbp)
jmp    1229 <check_for_user+0xb9>
jmp    11c9 <check_for_user+0x59>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %rax,%r12
lea    0x2(%rax),%r13
mov    %r13,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <check_for_user+0x45>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1070 <errx@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1080 <fgets@plt>
xor    %ebp,%ebp
jmp    11de <check_for_user+0x6e>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1202 <check_for_user+0x92>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11d0 <check_for_user+0x60>
cmpb   $0xa,(%rbx,%r12,1)
jne    11d0 <check_for_user+0x60>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [25 x i8] c"virtual memory exhausted\00"
define i32 @check_for_user(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = add i64 %10, 2
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @errx(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %2
br label %18
18: ; preds = %39, %17
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = add i64 %20, 2
%22 = load i32*, i32** %3
%23 = call i32* @fgets(i8* %19, i64 %21, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %40
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = call i64 @strncmp(i8* %26, i8* %27, i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 1, i32* %7
br label %40
39: ; preds = %31, %25
br label %18
40: ; preds = %38, %18
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** %5
%44 = call i32 @free(i8* %43)
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [25 x i8] c"virtual memory exhausted\00"
define i32 @check_for_user(i32* nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add i64 %3, 2
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @errx(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds i8, i8* %5, i64 %3
%12 = tail call i32* @fgets(i8* %5, i64 %4, i32* %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %23, label %14
14: ; preds = %10, %20
%15 = tail call i64 @strncmp(i8* %1, i8* %5, i64 %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8, i8* %11
%19 = icmp eq i8 %18, 10
br i1 %19, label %23, label %20
20: ; preds = %17, %14
%21 = tail call i32* @fgets(i8* %5, i64 %4, i32* %0)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %14
23: ; preds = %20, %17, %10
%24 = phi i32 [ 0, %10 ], [ 1, %17 ], [ 0, %20 ]
%25 = tail call i32 @fclose(i32* %0)
%26 = tail call i32 @free(i8* %5)
ret i32 %24
}