#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 */
typedef int /*<<< orphan*/ loff_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ pwrite(int, char *, int, int);
int main() {
  int fd;
  loff_t res;
  char buf[64], buf1[32], buf2[32], buf3[32];
  fd = open("foobar1", O_WRONLY | O_CREAT, 0666);
  pwrite(fd, "Hello Again", 11, 12);
  pwrite(-1, "Hello Again", 11, 12);
  pwrite(fd, (void *)-1, 11, 12);
  pwrite(-1, NULL, -1, 12);
  pwrite(fd, "Hello Again", 11, -1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    0x2ea6(%rip),%rax
or     (%rax),%esi
lea    0xea5(%rip),%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe96(%rip),%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    $0xffffffff,%edi
lea    0xe7b(%rip),%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    $0xffffffff,%edx
xor    %eax,%eax
mov    %eax,%esi
mov    $0xc,%ecx
mov    %edx,%edi
call   1040 <pwrite@plt>
mov    -0x8(%rbp),%edi
lea    0xe34(%rip),%rsi
mov    $0xb,%edx
mov    $0xffffffff,%ecx
call   1040 <pwrite@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e95(%rip),%rax
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb3(%rip),%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xea8(%rip),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    $0xffffffff,%edi
mov    %r14,%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
mov    $0xc,%ecx
call   1040 <pwrite@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xb,%edx
mov    $0xffffffff,%ecx
call   1040 <pwrite@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"Hello Again\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
store i32 0, i32* %1
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10, i32 438)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @pwrite(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 12)
%14 = call i32 @pwrite(i32 -1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 12)
%15 = load i32, i32* %2
%16 = call i32 @pwrite(i32 %15, i8* inttoptr (i64 -1 to i8*), i32 11, i32 12)
%17 = call i32 @pwrite(i32 -1, i8* null, i32 -1, i32 12)
%18 = load i32, i32* %2
%19 = call i32 @pwrite(i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 -1)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"Hello Again\00"
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438)
%5 = tail call i32 @pwrite(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 12)
%6 = tail call i32 @pwrite(i32 -1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 12)
%7 = tail call i32 @pwrite(i32 %4, i8* inttoptr (i64 -1 to i8*), i32 11, i32 12)
%8 = tail call i32 @pwrite(i32 -1, i8* null, i32 -1, i32 12)
%9 = tail call i32 @pwrite(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 -1)
%10 = tail call i32 @close(i32 %4)
ret i32 0
}