#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_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  const char *file = "test.tmp";
  int fd = open(file, O_WRONLY | O_CREAT,
                S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH);
  if (fd != -1) {
    write(fd, "abc", 3);
    lseek(fd, 6, SEEK_SET);
    write(fd, "def", 3);
    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)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
or     (%rax),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
mov    0x2e29(%rip),%rax
or     (%rax),%edx
mov    0x2e50(%rip),%rax
or     (%rax),%edx
mov    0x2e27(%rip),%rax
or     (%rax),%edx
mov    0x2e16(%rip),%rax
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11fc <main+0xbc>
mov    -0x1c(%rbp),%edi
lea    0xe49(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    0xe23(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e58(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e74(%rip),%rax
or     (%rax),%edx
mov    0x2e4b(%rip),%rax
or     (%rax),%edx
mov    0x2e3a(%rip),%rax
or     (%rax),%edx
lea    0xe79(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d5 <main+0x95>
mov    %eax,%ebx
lea    0xe6f(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x6,%esi
call   1040 <lseek@plt>
lea    0xe4b(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.tmp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [4 x i8] c"abc\00"
@SEEK_SET = global i32 0
@.str.2 = [4 x i8] c"def\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %6
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWUSR
%13 = load i32, i32* @S_IRUSR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %8, i32 %11, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %34
24: ; preds = %2
%25 = load i32, i32* %7
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%27 = load i32, i32* %7
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @lseek(i32 %27, i32 6, i32 %28)
%30 = load i32, i32* %7
%31 = call i32 @write(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %24, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.tmp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [4 x i8] c"abc\00"
@SEEK_SET = global i32 0
@.str.2 = [4 x i8] c"def\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* @S_IWUSR
%7 = load i32, i32* @S_IRUSR
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IWGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %23, label %17
17: ; preds = %2
%18 = tail call i32 @write(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @lseek(i32 %15, i32 6, i32 %19)
%21 = tail call i32 @write(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%22 = tail call i32 @close(i32 %15)
br label %23
23: ; preds = %17, %2
ret i32 0
}