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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void create_file(const char *file_name) {
  static const char FILE_DATA[32] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,
                                     11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
                                     22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  FILE *f = fopen(file_name, "wb");
  if (!f) {
    fprintf(stderr, "*** Unable to create file \"%s\"\n", file_name);
    exit(1);
  }
  fwrite(FILE_DATA, 1, sizeof(FILE_DATA), f);
  fclose(f);
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <create_file+0x4e>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe94(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rcx
lea    0xe57(%rip),%rdi
mov    $0x1,%esi
mov    $0x20,%edx
call   1070 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1193 <create_file+0x43>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@create_file.FILE_DATA = internal constant [32 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F"
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"*** Unable to create file \22%s\22\0A\00"
define void @create_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32*, i32** %3
%15 = call i32 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @create_file.FILE_DATA, i64 0, i64 0), i32 1, i32 32, i32* %14)
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
ret void
}

LLVM IR (-O2):
@create_file.FILE_DATA = internal constant [32 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F"
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"*** Unable to create file \22%s\22\0A\00"
define void @create_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @create_file.FILE_DATA, i64 0, i64 0), i32 1, i32 32, i32* %2)
%10 = tail call i32 @fclose(i32* %2)
ret void
}