#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int);
int strlen(char *);
int createFile(char *src_file, char *trgt_file) {
  int fd;
  if ((fd = open(trgt_file, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) ==
      -1) {
    if (errno == 21) {
      (void)close(fd);
      strcpy(trgt_file + strlen(trgt_file), "/");
      strcpy(trgt_file + strlen(trgt_file), src_file);
      if ((fd = open(trgt_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {
        fprintf(stderr, "Unable to create 'trgt_file': %s\n", strerror(errno));
        exit(EXIT_FAILURE);
      }
    } else {
      fprintf(stderr, "Unable to create 'trgt_file': %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<createFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    0x2e53(%rip),%rax
or     (%rax),%esi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
mov    0x2e21(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12da <createFile+0x16a>
mov    0x2def(%rip),%rax
cmpl   $0x15,(%rax)
jne    129b <createFile+0x12b>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe05(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
mov    0x2d87(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1296 <createFile+0x126>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12d5 <createFile+0x165>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xd40(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12da <createFile+0x16a>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e50(%rip),%r15
mov    0x2e69(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
mov    0x2e53(%rip),%rax
or     (%rax),%esi
mov    0x2e02(%rip),%r13
mov    0x2e23(%rip),%rbp
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    1224 <createFile+0xb4>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
cmp    $0x15,%edi
jne    1233 <createFile+0xc3>
mov    $0xffffffff,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
lea    0xe12(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%r12),%esi
or     (%r15),%esi
mov    0x0(%rbp),%edx
or     0x0(%r13),%edx
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     123e <createFile+0xce>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d86(%rip),%rax
mov    (%rax),%ebx
jmp    1250 <createFile+0xe0>
mov    0x2d7b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xda6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Unable to create 'trgt_file': %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @createFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %6, i32 %11, i32 %14)
store i32 %15, i32* %5
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %61
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = icmp eq i32 %18, 21
br i1 %19, label %20, label %53
20: ; preds = %17
%21 = load i32, i32* %5
%22 = call i32 @close(i32 %21)
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8*, i8** %3
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %4
%37 = load i32, i32* @O_RDWR
%38 = load i32, i32* @O_CREAT
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IRUSR
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %40, %41
%43 = call i32 @open(i8* %36, i32 %39, i32 %42)
store i32 %43, i32* %5
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %52
45: ; preds = %20
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %20
br label %60
53: ; preds = %17
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %52
br label %61
61: ; preds = %60, %2
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Unable to create 'trgt_file': %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @createFile(i8* %0, i8* %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %1, i32 %7, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %47
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = icmp eq i32 %14, 21
br i1 %15, label %16, label %41
16: ; preds = %13
%17 = tail call i32 @close(i32 -1)
%18 = tail call i32 @strlen(i8* %1)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = tail call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @strlen(i8* %1)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* %0)
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IWUSR
%31 = or i32 %30, %29
%32 = tail call i32 @open(i8* %1, i32 %28, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %47
34: ; preds = %16
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %13
%42 = load i32, i32* @stderr
%43 = tail call i8* @strerror(i32 %14)
%44 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %16, %2
%48 = phi i32 [ %32, %16 ], [ %11, %2 ]
ret i32 %48
}