#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_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = open("./hello", O_CREAT | O_TRUNC | O_RDWR);
  lseek(fd, 10, SEEK_SET);
  write(fd, "world123", 16);
  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    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xe68(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xa,%esi
call   1040 <lseek@plt>
lea    0xe82(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"./hello\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [9 x i8] c"world123\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = load i32, i32* @O_RDWR
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 10, i32 %14)
%16 = load i32, i32* %6
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 16)
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"./hello\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [9 x i8] c"world123\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_RDWR
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %8, i32 10, i32 %9)
%11 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 16)
%12 = tail call i32 @close(i32 %8)
ret i32 0
}