#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 O_CREAT;
int O_RDWR;
int open(char *, int, int);
int write(int, char *, int);
int make_file(char *name) {
  int fd;
  fd = open(name, O_RDWR | O_CREAT, 0666);
  if (fd < 0)
    return -1;
  if (write(fd, "chroot-file-contents", sizeof("chroot-file-contents")) !=
      sizeof("chroot-file-contents"))
    return -1;
  return fd;
}


x86 assembly (clang, -O0):
<make_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2eb8(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1165 <make_file+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <make_file+0x77>
mov    -0x14(%rbp),%edi
lea    0xe91(%rip),%rsi
mov    $0x15,%edx
call   1030 <write@plt>
cltq
cmp    $0x15,%rax
je     1191 <make_file+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <make_file+0x77>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_file>:
push   %rbx
mov    0x2eb8(%rip),%rax
mov    0x2ec9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
test   %eax,%eax
js     1163 <make_file+0x43>
mov    %eax,%ebx
lea    0xeb6(%rip),%rsi
mov    %eax,%edi
mov    $0x15,%edx
call   1030 <write@plt>
cmp    $0x15,%eax
mov    $0xffffffff,%eax
cmove  %ebx,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [21 x i8] c"chroot-file-contents\00"
define i32 @make_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8, i32 438)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %21
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 21)
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %16, 21
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %2
br label %21
19: ; preds = %13
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %18, %12
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [21 x i8] c"chroot-file-contents\00"
define i32 @make_file(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4, i32 438)
%6 = icmp slt i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 21)
%9 = icmp eq i32 %8, 21
%10 = select i1 %9, i32 %5, i32 -1
br label %11
11: ; preds = %7, %1
%12 = phi i32 [ -1, %1 ], [ %10, %7 ]
ret i32 %12
}