#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int checkcmp() {
  FILE *cmp;
  char buf[400];
  cmp = fopen("tools/.chk", "r");
  if (cmp != NULL) {
    if (fgets(buf, sizeof(buf), cmp) != NULL) {
      fclose(cmp);
      return 0x1;
    }
    fclose(cmp);
  }
  return 0x0;
}


x86 assembly (clang, -O0):
<checkcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
lea    0xebe(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119a <checkcmp+0x6a>
lea    -0x1a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x190,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1191 <checkcmp+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <checkcmp+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkcmp>:
push   %rbp
push   %rbx
sub    $0x198,%rsp
lea    0xec0(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1177 <checkcmp+0x47>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x190,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1179 <checkcmp+0x49>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x198,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"tools/.chk\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkcmp() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [400 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %18
7: ; preds = %0
%8 = getelementptr inbounds [400 x i8], [400 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i32* @fgets(i8* %8, i32 400, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
store i32 1, i32* %1
br label %19
15: ; preds = %7
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %15, %0
store i32 0, i32* %1
br label %19
19: ; preds = %18, %12
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [11 x i8] c"tools/.chk\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkcmp() {
%1 = alloca [400 x i8]
%2 = getelementptr inbounds [400 x i8], [400 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 400, i32* %3)
%7 = icmp ne i32* %6, null
%8 = call i32 @fclose(i32* %3)
%9 = zext i1 %7 to i32
br label %10
10: ; preds = %5, %0
%11 = phi i32 [ 0, %0 ], [ %9, %5 ]
ret i32 %11
}