#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;
int atoi(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fwrite(int const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "expecting integer argument!\n");
    return EXIT_FAILURE;
  }
  const int value = atoi(argv[1]);
  FILE *fp = fopen("test-int", "wb");
  if (!fp) {
    fprintf(stderr, "could not open 'test-int' file for writing!\n");
    return EXIT_FAILURE;
  }
  if (fwrite(&value, sizeof(int), 1, fp) != 1) {
    fprintf(stderr, "oh noes!  write failed!\n");
    fclose(fp);
    return EXIT_FAILURE;
  }
  if (fclose(fp) != 0) {
    fprintf(stderr, "file close failed; data didn't make it to disk\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x46>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ee <main+0x9e>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     123d <main+0xed>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1276 <main+0x126>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    0x2d53(%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   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11bd <main+0x6d>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,0xc(%rsp)
lea    0xeaf(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cf <main+0x7f>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
jne    11f3 <main+0xa3>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     1212 <main+0xc2>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
jmp    11df <main+0x8f>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
jmp    11df <main+0x8f>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11e4 <main+0x94>
mov    0x2db7(%rip),%rax
jmp    11eb <main+0x9b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"expecting integer argument!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"test-int\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [45 x i8] c"could not open 'test-int' file for writing!\0A\00"
@.str.4 = [25 x i8] c"oh noes! write failed!\0A\00"
@.str.5 = [48 x i8] c"file close failed; data didn't make it to disk\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %46
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp ne i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %3
br label %46
26: ; preds = %14
%27 = load i32*, i32** %7
%28 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %27)
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32*, i32** %7
%34 = call i64 @fclose(i32* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %46
36: ; preds = %26
%37 = load i32*, i32** %7
%38 = call i64 @fclose(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %46
44: ; preds = %36
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %40, %30, %22, %10
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"expecting integer argument!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"test-int\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [45 x i8] c"could not open 'test-int' file for writing!\0A\00"
@.str.4 = [25 x i8] c"oh noes! write failed!\0A\00"
@.str.5 = [48 x i8] c"file close failed; data didn't make it to disk\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
br label %35
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
store i32 %13, i32* %3
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %32
19: ; preds = %9
%20 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %14)
%21 = icmp eq i32 %20, 1
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i64 @fclose(i32* %14)
br label %32
26: ; preds = %19
%27 = tail call i64 @fclose(i32* %14)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %26, %29, %22, %16
%33 = phi i32* [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %26 ]
%34 = load i32, i32* %33
br label %35
35: ; preds = %32, %5
%36 = phi i32 [ %8, %5 ], [ %34, %32 ]
ret i32 %36
}