#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int fd, n;
  char str[] = "hello";
  if ((fd = open("/dev/sbulla", O_RDWR)) < 0) {
    perror("open erro\n");
  }
  n = strlen(str);
  printf("fd=%d n=%d\n", fd, n);
  lseek(fd, 5120, SEEK_SET);
  write(fd, str, n);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7b(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xe75(%rip),%ax
mov    %ax,-0xe(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c0 <main+0x50>
lea    0xe57(%rip),%rdi
call   1090 <perror@plt>
lea    -0x12(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    $0x1400,%esi
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0x6f,0xc(%rsp)
movl   $0x6c6c6568,0x8(%rsp)
6c
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11f4 <main+0x84>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x1400,%esi
call   1060 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe17(%rip),%rdi
call   1090 <perror@plt>
jmp    11a2 <main+0x32>

LLVM IR (-O0):
@__const.main.str = [6 x i8] c"hello\00"
@.str = [12 x i8] c"/dev/sbulla\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open erro\0A\00"
@.str.2 = [12 x i8] c"fd=%d n=%d\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
store i32 0, i32* %1
%5 = bitcast [6 x i8]* %4 to i8*
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15)
%17 = load i32, i32* %2
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @lseek(i32 %17, i32 5120, i32 %18)
%20 = load i32, i32* %2
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@__const.main.str = [6 x i8] c"hello\00"
@.str = [12 x i8] c"/dev/sbulla\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open erro\0A\00"
@.str.2 = [12 x i8] c"fd=%d n=%d\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @strlen(i8* %2)
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %9)
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @lseek(i32 %4, i32 5120, i32 %11)
%13 = call i32 @write(i32 %4, i8* %2, i32 %9)
%14 = call i32 @close(i32 %4)
ret i32 0
}