#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*/ cstrcat(char *, char *, int);
int /*<<< orphan*/ cstrcpy(char *, char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char *);
FILE *create_file(char *name) {
  FILE *f;
  char filename[1024];
  cstrcpy(filename, name, 1024);
  cstrcat(filename, ".new", 1024);
  if ((f = fopen(filename, "w")) == NULL) {
    printf("failed to create file %s\n", filename);
    return NULL;
  }
  fprintf(f, "version=1\n");
  return f;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1060 <cstrcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x400,%edx
call   1070 <cstrcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <create_file+0x7d>
lea    -0x420(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <create_file+0x95>
mov    -0x18(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%edx
call   1050 <cstrcpy@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   1070 <cstrcat@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b1 <create_file+0x61>
lea    0xe82(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
jmp    11c0 <create_file+0x70>
lea    0xe4d(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c".new\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"failed to create file %s\0A\00"
@.str.3 = [11 x i8] c"version=1\0A\00"
define i32* @create_file(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
store i8* %0, i8** %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @cstrcpy(i8* %6, i8* %7, i32 1024)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @cstrcat(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1024)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %15)
store i32* null, i32** %2
br label %21
17: ; preds = %1
%18 = load i32*, i32** %4
%19 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32*, i32** %4
store i32* %20, i32** %2
br label %21
21: ; preds = %17, %14
%22 = load i32*, i32** %2
ret i32* %22
}

LLVM IR (-O2):
@.str = [5 x i8] c".new\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"failed to create file %s\0A\00"
@.str.3 = [11 x i8] c"version=1\0A\00"
define noalias i32* @create_file(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @cstrcpy(i8* %3, i8* %0, i32 1024)
%5 = call i32 @cstrcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1024)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %12
10: ; preds = %1
%11 = call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 10, i64 1, i32* %6)
br label %12
12: ; preds = %10, %8
ret i32* %6
}