#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*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int exist(char *name) {
  FILE *ptr;
  char buf[64], tama[16 + 1];
  if ((ptr = fopen("tamas", "r")) == NULL)
    return -1;
  strncpy(tama, name, 16);
  strcat(tama, ":");
  while (fgets(buf, 64, ptr) != NULL)
    if (strstr(buf, tama) == buf) {
      fclose(ptr);
      return 0;
    }
  fclose(ptr);
  return -1;
}


x86 assembly (clang, -O0):
<exist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <exist+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <exist+0xbe>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120e <exist+0xae>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1080 <strstr@plt>
lea    -0x60(%rbp),%rcx
cmp    %rcx,%rax
jne    1209 <exist+0xa9>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <exist+0xbe>
jmp    11be <exist+0x5e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exist>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rbx
lea    0xe7d(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f3 <exist+0x83>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xe57(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcat@plt>
lea    0x20(%rsp),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11fa <exist+0x8a>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11c0 <exist+0x50>
xor    %ebx,%ebx
jmp    11ff <exist+0x8f>
mov    $0xffffffff,%ebx
jmp    1207 <exist+0x97>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"tamas\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
define i32 @exist(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca [17 x i8]
store i8* %0, i8** %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %34
10: ; preds = %1
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 16)
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %30, %10
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i32* @fgets(i8* %17, i32 64, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%24 = call i8* @strstr(i8* %22, i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %2
br label %34
30: ; preds = %21
br label %16
31: ; preds = %16
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 -1, i32* %2
br label %34
34: ; preds = %31, %27, %9
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"tamas\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
define i32 @exist(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %1
%9 = call i32 @strncpy(i8* %5, i8* %0, i32 16)
%10 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %14, %8
%12 = call i32* @fgets(i8* %4, i32 64, i32* %6)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = call i64 @strlen(i8* %5)
%16 = call i32 @strncmp(i8* %4, i8* %5, i64 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %11, %14
%19 = phi i32 [ 0, %14 ], [ -1, %11 ]
%20 = call i32 @fclose(i32* %6)
br label %21
21: ; preds = %18, %1
%22 = phi i32 [ -1, %1 ], [ %19, %18 ]
ret i32 %22
}