#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*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ panic(char *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
bool check_for_user(FILE *fp, const char *name) {
  char *buffer;
  size_t len;
  bool found = false;
  len = strlen(name);
  if ((buffer = malloc(len + 2)) == NULL)
    panic("Insufficient virtual memory");
  while (fgets(buffer, (int)len + 2, fp) != NULL) {
    if (strncmp(name, buffer, len) == 0 && buffer[len] == '\n') {
      found = true;
      break;
    }
  }
  (void)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    11bb <check_for_user+0x4b>
lea    0xe4a(%rip),%rdi
call   1070 <panic@plt>
jmp    11c0 <check_for_user+0x50>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
add    $0x2,%esi
mov    -0x8(%rbp),%rdx
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1221 <check_for_user+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    121c <check_for_user+0xac>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    121c <check_for_user+0xac>
movl   $0x1,-0x24(%rbp)
jmp    1221 <check_for_user+0xb1>
jmp    11c0 <check_for_user+0x50>
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),%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <check_for_user+0x39>
lea    0xe5c(%rip),%rdi
call   1070 <panic@plt>
lea    0x2(%r12),%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
xor    %r13d,%r13d
jmp    11cd <check_for_user+0x5d>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     11f2 <check_for_user+0x82>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11c0 <check_for_user+0x50>
cmpb   $0xa,(%rbx,%r12,1)
jne    11c0 <check_for_user+0x50>
mov    $0x1,%r13d
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Insufficient virtual memory\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 %16
14: ; preds = %2
%15 = call i32 @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
br label %17
17: ; preds = %39, %16
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i32
%21 = add nsw i32 %20, 2
%22 = load i32*, i32** %3
%23 = call i32* @fgets(i8* %18, i32 %21, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %40
25: ; preds = %17
%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 %17
40: ; preds = %38, %17
%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):
@.str = [28 x i8] c"Insufficient virtual memory\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 %9
7: ; preds = %2
%8 = tail call i32 @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds i8, i8* %5, i64 %3
%11 = trunc i64 %3 to i32
%12 = add nsw i32 %11, 2
%13 = tail call i32* @fgets(i8* %5, i32 %12, i32* %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %24, label %15
15: ; preds = %9, %21
%16 = tail call i64 @strncmp(i8* %1, i8* %5, i64 %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8, i8* %10
%20 = icmp eq i8 %19, 10
br i1 %20, label %24, label %21
21: ; preds = %18, %15
%22 = tail call i32* @fgets(i8* %5, i32 %12, i32* %0)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %15
24: ; preds = %21, %18, %9
%25 = phi i32 [ 0, %9 ], [ 1, %18 ], [ 0, %21 ]
%26 = tail call i32 @fclose(i32* %0)
%27 = tail call i32 @free(i8* %5)
ret i32 %25
}