#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_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int, int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = open("/tmp/file", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
  assert(fd > -1);
  int rc = write(fd, "hello world\n", 13);
  assert(rc == 13);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e92(%rip),%rax
or     (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%edi
lea    0xe66(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xd,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
lea    0xe84(%rip),%rsi
mov    %ebx,%edi
mov    $0xd,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0xd,%eax
sete   %dil
call   1050 <assert@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRWXU
%14 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, -1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 13)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 13
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%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_IRWXU
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = xor i32 %9, -1
%11 = lshr i32 %10, 31
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 13)
%14 = icmp eq i32 %13, 13
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @close(i32 %9)
ret i32 0
}