#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*/ off_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ atoll(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3 || strcmp(argv[1], "--help") == 0) {
    fprintf(stderr, "Usage: %s pathname offset\n", argv[0]);
    return 1;
  }
  int fd = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    fprintf(stderr, "Error when invoking open64: %s\n", strerror(errno));
  }
  off_t off = atoll(argv[2]);
  if (lseek(fd, off, SEEK_SET) == -1) {
    fprintf(stderr, "Error when invoking lseek: %s\n", strerror(errno));
    return 1;
  }
  if (write(fd, "test", 4) == -1) {
    fprintf(stderr, "Error when invoking write: %s\n", strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11ae <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <main+0x66>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe42(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1301 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    0x2dd8(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1240 <main+0xd0>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xde7(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoll@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    12a5 <main+0x135>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1301 <main+0x191>
mov    -0x14(%rbp),%edi
lea    0xdb2(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    12fa <main+0x18a>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xd7d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1301 <main+0x191>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1253 <main+0xe3>
mov    0x8(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1253 <main+0xe3>
mov    0x8(%rbx),%rdi
mov    0x2e3c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfa(%rip),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11f7 <main+0x87>
mov    0x2df4(%rip),%rax
mov    (%rax),%r14d
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe36(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x10(%rbx),%rdi
call   1050 <atoll@plt>
mov    0x2db1(%rip),%rcx
mov    (%rcx),%edx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1268 <main+0xf8>
lea    0xe43(%rip),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1295 <main+0x125>
mov    0x2d8e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe15(%rip),%rsi
jmp    1286 <main+0x116>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xda1(%rip),%rsi
jmp    128b <main+0x11b>
mov    0x2d59(%rip),%rax
mov    (%rax),%ebx
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdbc(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Usage: %s pathname offset\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [32 x i8] c"Error when invoking open64: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [31 x i8] c"Error when invoking lseek: %s\0A\00"
@.str.4 = [5 x i8] c"test\00"
@.str.5 = [31 x i8] c"Error when invoking write: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10, %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %65
22: ; preds = %10
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_CREAT
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IWUSR
%31 = or i32 %29, %30
%32 = call i32 @open(i8* %25, i32 %28, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %22
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %35, %22
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @atoll(i8* %43)
store i32 %44, i32* %7
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @lseek(i32 %45, i32 %46, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %40
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %53)
store i32 1, i32* %3
br label %65
55: ; preds = %40
%56 = load i32, i32* %6
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %62)
store i32 1, i32* %3
br label %65
64: ; preds = %55
store i32 0, i32* %3
br label %65
65: ; preds = %64, %59, %50, %16
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Usage: %s pathname offset\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [32 x i8] c"Error when invoking open64: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [31 x i8] c"Error when invoking lseek: %s\0A\00"
@.str.4 = [5 x i8] c"test\00"
@.str.5 = [31 x i8] c"Error when invoking write: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4, %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %48
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %19, %18
%21 = tail call i32 @open(i8* %14, i32 %17, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %23, %13
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @atoll(i8* %30)
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @lseek(i32 %21, i32 %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %48
40: ; preds = %28
%41 = tail call i32 @write(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %35, %43, %40, %9
%49 = phi i32 [ 1, %9 ], [ 1, %35 ], [ 1, %43 ], [ 0, %40 ]
ret i32 %49
}