#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_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
int main() {
  int fq = open("hole.tet", O_RDWR | O_CREAT | O_EXCL, 0644);
  if (-1 == fq)
    perror("open");
  int len = write(fq, "hello", 5);
  lseek(fq, 12, SEEK_CUR);
  len = write(fq, "world", 5);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1198 <main+0x58>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%edi
lea    0xe6c(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    0xe45(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6e(%rip),%rax
or     (%rax),%esi
lea    0xe9d(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11b3 <main+0x73>
lea    0xe93(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xc,%esi
call   1040 <lseek@plt>
lea    0xe71(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
jmp    1174 <main+0x34>

LLVM IR (-O0):
@.str = [9 x i8] c"hole.tet\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"hello\00"
@SEEK_CUR = global i32 0
@.str.3 = [6 x i8] c"world\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_EXCL
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i32 420)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* %2
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* @SEEK_CUR
%19 = call i32 @lseek(i32 %17, i32 12, i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
store i32 %21, i32* %3
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"hole.tet\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"hello\00"
@SEEK_CUR = global i32 0
@.str.3 = [6 x i8] c"world\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = load i32, i32* @O_EXCL
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 420)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%12 = load i32, i32* @SEEK_CUR
%13 = tail call i32 @lseek(i32 %6, i32 12, i32 %12)
%14 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
ret i32 0
}