#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int create_file(char *filename, char *mode) {
  FILE *f;
  char buffer[128];
  if (!(f = fopen(filename, "w")))
    return 0;
  fclose(f);
  if (mode) {
    sprintf(buffer, "chmod %s %s", mode, filename);
    system(buffer);
  }
  return 1;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117d <create_file+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11bf <create_file+0x7f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     11b8 <create_file+0x78>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe5b(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <system@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <create_file+0x58>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
test   %r14,%r14
je     119a <create_file+0x5a>
lea    0xe85(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1040 <system@plt>
jmp    119a <create_file+0x5a>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [12 x i8] c"chmod %s %s\00"
define i32 @create_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [128 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %25
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = call i32 @fclose(i32* %13)
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = load i8*, i8** %4
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%23 = call i32 @system(i8* %22)
br label %24
24: ; preds = %17, %12
store i32 1, i32* %3
br label %25
25: ; preds = %24, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [12 x i8] c"chmod %s %s\00"
define i32 @create_file(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call i32 @fclose(i32* %5)
%9 = icmp eq i8* %1, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
%12 = call i32 @system(i8* %4)
br label %13
13: ; preds = %7, %10, %2
%14 = phi i32 [ 0, %2 ], [ 1, %10 ], [ 1, %7 ]
ret i32 %14
}