#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, char *, char *, int, int);
int /*<<< orphan*/ perror(char *);
int main(void) {
  FILE *finb = NULL;
  finb = fopen("/proc/"
               "kwrite_test",
               "rb");
  if (finb == NULL)
    goto exit_no_file;
  if (input(finb, 1000000, 27169, 975835, ((char *)0x02f28000),
            ((char *)0x100000ff), -12341, 9774))
    goto exit_fail;
  if (fclose(finb)) {
    finb = 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 (finb)
    fclose(finb);
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <main+0x3e>
jmp    11f1 <main+0xb1>
mov    -0x10(%rbp),%rdi
mov    $0xf4240,%esi
mov    $0x6a21,%edx
mov    $0xee3db,%ecx
mov    $0x2f28000,%r8d
mov    $0x100000ff,%r9d
movl   $0xffffcfcb,(%rsp)
movl   $0x262e,0x8(%rsp)
call   1030 <input@plt>
cmp    $0x0,%rax
je     11c0 <main+0x80>
jmp    120e <main+0xce>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11e0 <main+0xa0>
movq   $0x0,-0x10(%rbp)
jmp    1202 <main+0xc2>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <main+0xee>
lea    0xe1d(%rip),%rdi
call   1060 <perror@plt>
jmp    120e <main+0xce>
lea    0xe1f(%rip),%rdi
call   1060 <perror@plt>
cmpq   $0x0,-0x10(%rbp)
je     1222 <main+0xe2>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11bf <main+0x7f>
mov    %rax,%rbx
mov    $0x2f28000,%r8d
mov    $0x100000ff,%r9d
mov    %rax,%rdi
mov    $0xf4240,%esi
mov    $0x6a21,%edx
mov    $0xee3db,%ecx
push   $0x262e
push   $0xffffffffffffcfcb
call   1030 <input@plt>
add    $0x10,%rsp
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     11a9 <main+0x69>
mov    0x2e39(%rip),%rax
jmp    11b5 <main+0x75>
test   %rax,%rax
jne    11c8 <main+0x88>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4f(%rip),%rdi
jmp    11cf <main+0x8f>
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
jmp    11a0 <main+0x60>

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/kwrite_test\00"
@.str.1 = [3 x i8] c"rb\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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 27169, i32 975835, i8* inttoptr (i64 49446912 to i8*), i8* inttoptr (i64 268435711 to i8*), i32 -12341, i32 9774)
%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 = [18 x i8] c"/proc/kwrite_test\00"
@.str.1 = [3 x i8] c"rb\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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 27169, i32 975835, i8* inttoptr (i64 49446912 to i8*), i8* inttoptr (i64 268435711 to i8*), i32 -12341, i32 9774)
%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
}