#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 */
scalar_t__ doesFileExist(char const *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int createFile(const char *path, char *filename) {
  if (path == NULL || filename == NULL) {
    printf("ERROR: Could not read filesystem\n");
    return 0;
  }
  char name[255];
  name[0] = 0;
  strncat(name, path, 255);
  strncat(name, filename, 255);
  if (doesFileExist(path, filename)) {
    filename[strlen(filename) - 1] = 0;
    printf("ERROR: File with the name %s already exists\n", filename);
    return 0;
  }
  FILE *file = fopen(name, "w");
  fclose(file);
  return 1;
}


x86 assembly (clang, -O0):
<createFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <createFile+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <createFile+0x43>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <createFile+0xfd>
movb   $0x0,-0x120(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <doesFileExist@plt>
cmp    $0x0,%rax
je     1230 <createFile+0xd0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x130(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <createFile+0xfd>
lea    -0x120(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
test   %rdi,%rdi
je     11e8 <createFile+0x78>
mov    %rsi,%r14
test   %rsi,%rsi
je     11e8 <createFile+0x78>
mov    %rdi,%rbx
movb   $0x0,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <doesFileExist@plt>
test   %rax,%rax
je     11f8 <createFile+0x88>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xe26(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1214 <createFile+0xa4>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1214 <createFile+0xa4>
lea    0xe2e(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"ERROR: Could not read filesystem\0A\00"
@.str.1 = [45 x i8] c"ERROR: File with the name %s already exists\0A\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @createFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [255 x i8]
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %41
15: ; preds = %10
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
store i8 0, i8* %16
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strncat(i8* %17, i8* %18, i32 255)
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 @strncat(i8* %20, i8* %21, i32 255)
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = call i64 @doesFileExist(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %15
%28 = load i8*, i8** %5
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %34)
store i32 0, i32* %3
br label %41
36: ; preds = %15
%37 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
store i32 1, i32* %3
br label %41
41: ; preds = %36, %27, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [45 x i8] c"ERROR: File with the name %s already exists\0A\00"
@.str.2 = [2 x i8] c"w\00"
@str = [33 x i8] c"ERROR: Could not read filesystem\00"
define i32 @createFile(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %26
9: ; preds = %2
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 0, i8* %10
%11 = call i32 @strncat(i8* %10, i8* %0, i32 255)
%12 = call i32 @strncat(i8* %10, i8* %1, i32 255)
%13 = call i64 @doesFileExist(i8* %0, i8* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = call i32 @strlen(i8* %1)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %24
21: ; preds = %9
%22 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @fclose(i32* %22)
br label %24
24: ; preds = %21, %15
%25 = phi i32 [ 0, %15 ], [ 1, %21 ]
br label %26
26: ; preds = %24, %7
%27 = phi i32 [ 0, %7 ], [ %25, %24 ]
ret i32 %27
}