#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*/ a;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *filename = "num.bin";
  int a = 0x12345678;
  FILE *fp = fopen(filename, "wb");
  if (fp) {
    fwrite(&a, sizeof(a), 1, fp);
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x12345678,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a5 <main+0x65>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11b5 <main+0x75>
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x12345678,0xc(%rsp)
12
lea    0xeac(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1189 <main+0x49>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    119c <main+0x5c>
lea    0xe7b(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"num.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 305419896, i32* %3
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32*, i32** %4
%11 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %10)
%12 = load i32*, i32** %4
%13 = call i32 @fclose(i32* %12)
br label %17
14: ; preds = %0
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"num.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 305419896, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %3)
%7 = tail call i32 @fclose(i32* %3)
br label %10
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
ret i32 0
}