#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int check_file(char *elem_name, char *file_name) {
  int res = -1;
  char temp_name[1024];
  FILE *stream = fopen(file_name, "r");
  if (stream == NULL) {
    res = 0;
  } else {
    if (fgets(temp_name, 1024, stream)) {
      temp_name[strlen(temp_name) - 1] = 0;
      if (strcmp(temp_name, elem_name) == 0) {
        res = 1;
      }
    }
    fclose(stream);
  }
  return res;
}


x86 assembly (clang, -O0):
<check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    119b <check_file+0x4b>
movl   $0x0,-0x14(%rbp)
jmp    1208 <check_file+0xb8>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fc <check_file+0xac>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <check_file+0xa7>
movl   $0x1,-0x14(%rbp)
jmp    11fc <check_file+0xac>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe96(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b7 <check_file+0x67>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11bb <check_file+0x6b>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
neg    %rax
sbb    %ebp,%ebp
or     $0x1,%ebp
jmp    11c0 <check_file+0x70>
xor    %ebp,%ebp
jmp    11c8 <check_file+0x78>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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