#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*/ O_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
void writefile(const char *path, const char *str) {
  int fd = open(path, O_WRONLY);
  assert(fd >= 0);
  assert(write(fd, str, strlen(str)) == strlen(str));
  close(fd);
}


x86 assembly (clang, -O0):
<writefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writefile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x2e7a(%rip),%rax
mov    (%rax),%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    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %rax,%r14
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
define void @writefile(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** %3
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = call i64 @write(i32 %13, i8* %14, i64 %16)
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
%20 = icmp eq i64 %17, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
define void @writefile(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = xor i32 %4, -1
%6 = lshr i32 %5, 31
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = tail call i64 @write(i32 %4, i8* %1, i64 %8)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = icmp eq i64 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @close(i32 %4)
ret void
}