#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_EXCL;
int O_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int strlen(char const *);
int write(int, char const *, int);
void create_file(const char *path, const char *buffer, int mode) {
  int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
  assert(fd >= 0);
  int err = write(fd, buffer, sizeof(char) * strlen(buffer));
  assert(err == (sizeof(char) * strlen(buffer)));
  close(fd);
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
mov    -0x14(%rbp),%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e6d(%rip),%rcx
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%rbx
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %eax,%r14d
sete   %dil
call   1060 <assert@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define void @create_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_EXCL
%14 = or i32 %12, %13
%15 = load i32, i32* %6
%16 = call i32 @open(i8* %9, i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp sge i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %7
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @write(i32 %21, i8* %22, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = icmp eq i64 %30, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* %7
%39 = call i32 @close(i32 %38)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define void @create_file(i8* nocapture %0, i8* %1, i32 %2) {
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_EXCL
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8, i32 %2)
%10 = xor i32 %9, -1
%11 = lshr i32 %10, 31
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @strlen(i8* %1)
%14 = tail call i32 @write(i32 %9, i8* %1, i32 %13)
%15 = tail call i32 @strlen(i8* %1)
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @close(i32 %9)
ret void
}