#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ input(int /*<<< orphan*/ *, int, int, int, int, int);
int /*<<< orphan*/ perror(char *);
int main(void) {
  FILE *fin = NULL;
  fin = fopen("/proc/"
              "kputs_test",
              "r");
  if (fin == NULL)
    goto exit_no_file;
  if (input(fin, 1000000, 1000000, 5, 27169, 123456))
    goto exit_fail;
  if (fclose(fin)) {
    fin = NULL;
    goto exit_bad_fclose;
  }
  return EXIT_SUCCESS;
exit_no_file:
  perror("error opening file");
  goto exit_fail;
exit_bad_fclose:
  perror("error closing file");
  goto exit_fail;
exit_fail:
  if (fin)
    fclose(fin);
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <main+0x3e>
jmp    11df <main+0x9f>
mov    -0x10(%rbp),%rdi
mov    $0xf4240,%edx
mov    $0x5,%ecx
mov    $0x6a21,%r8d
mov    $0x1e240,%r9d
mov    %edx,%esi
call   1030 <input@plt>
cmp    $0x0,%rax
je     11ae <main+0x6e>
jmp    11fc <main+0xbc>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11ce <main+0x8e>
movq   $0x0,-0x10(%rbp)
jmp    11f0 <main+0xb0>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <main+0xdc>
lea    0xe2d(%rip),%rdi
call   1060 <perror@plt>
jmp    11fc <main+0xbc>
lea    0xe2f(%rip),%rdi
call   1060 <perror@plt>
cmpq   $0x0,-0x10(%rbp)
je     1210 <main+0xd0>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b1 <main+0x71>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xf4240,%esi
mov    $0xf4240,%edx
mov    $0x5,%ecx
mov    $0x6a21,%r8d
mov    $0x1e240,%r9d
call   1030 <input@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     119b <main+0x5b>
mov    0x2e47(%rip),%rax
jmp    11a7 <main+0x67>
test   %rax,%rax
jne    11ba <main+0x7a>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rdi
jmp    11c1 <main+0x81>
lea    0xe65(%rip),%rdi
call   1060 <perror@plt>
jmp    1192 <main+0x52>

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/kputs_test\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [19 x i8] c"error opening file\00"
@.str.3 = [19 x i8] c"error closing file\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
%3 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
br label %19
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call i64 @input(i32* %8, i32 1000000, i32 1000000, i32 5, i32 27169, i32 123456)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
br label %23
12: ; preds = %7
%13 = load i32*, i32** %2
%14 = call i64 @fclose(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32* null, i32** %2
br label %21
17: ; preds = %12
%18 = load i32, i32* @EXIT_SUCCESS
store i32 %18, i32* %1
br label %31
19: ; preds = %6
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %19, %11
%24 = load i32*, i32** %2
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32*, i32** %2
%28 = call i64 @fclose(i32* %27)
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %1
br label %31
31: ; preds = %29, %17
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/kputs_test\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [19 x i8] c"error opening file\00"
@.str.3 = [19 x i8] c"error closing file\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = tail call i64 @input(i32* %1, i32 1000000, i32 1000000, i32 5, i32 27169, i32 123456)
%5 = icmp eq i64 %4, 0
%6 = tail call i64 @fclose(i32* %1)
br i1 %5, label %7, label %12
7: ; preds = %3
%8 = icmp eq i64 %6, 0
br i1 %8, label %12, label %9
9: ; preds = %0, %7
%10 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %0 ]
%11 = tail call i32 @perror(i8* %10)
br label %12
12: ; preds = %9, %3, %7
%13 = phi i32* [ @EXIT_SUCCESS, %7 ], [ @EXIT_FAILURE, %3 ], [ @EXIT_FAILURE, %9 ]
%14 = load i32, i32* %13
ret i32 %14
}