#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stdout;
void create_short_file(const char *filename) {
  FILE *file;
  if (!(file = fopen(filename, "w"))) {
    printf("create_short_file : fopen (%s, \"w\") failed.", filename);
    fflush(stdout);
    perror(NULL);
    exit(1);
  };
  fprintf(file, "This is the file data.\n");
  fclose(file);
}


x86 assembly (clang, -O0):
<create_short_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cb <create_short_file+0x5b>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_short_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b3 <create_short_file+0x43>
mov    %rax,%rbx
lea    0xe9c(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
lea    0xe48(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [44 x i8] c"create_short_file : fopen (%s, \22w\22) failed.\00"
@stdout = global i32 0
@.str.2 = [24 x i8] c"This is the file data.\0A\00"
define void @create_short_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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = call i32 @perror(i32* null)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [44 x i8] c"create_short_file : fopen (%s, \22w\22) failed.\00"
@stdout = global i32 0
@.str.2 = [24 x i8] c"This is the file data.\0A\00"
define void @create_short_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = tail call i32 @perror(i32* null)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 23, i64 1, i32* %2)
%12 = tail call i32 @fclose(i32* %2)
ret void
}