#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int ret = -1;
  int fd = -1;
  int buf_size = 8 * 1024 * 1024;
  char *buffer = NULL;
  off_t pos = 0;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <filename>\n", argv[0]);
    return (-1);
  }
  buffer = (char *)malloc(buf_size);
  if (!buffer) {
    perror("malloc");
    return (-1);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    return (-1);
  }
  ret = read(fd, buffer, buf_size);
  if (ret < 0) {
    perror("read");
    return (-1);
  };
  pos = lseek(fd, 0, SEEK_CUR);
  printf("lseek returned: %d\n", (int)pos);
  close(fd);
  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)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x800000,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ed <main+0x6d>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c3 <main+0x143>
mov    -0x1c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121c <main+0x9c>
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1257 <main+0xd7>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c3 <main+0x143>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    128b <main+0x10b>
lea    0xda8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c3 <main+0x143>
mov    -0x18(%rbp),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%esi
lea    0xd78(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11f3 <main+0x73>
mov    $0x800000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1219 <main+0x99>
mov    %rax,%rbp
mov    0x8(%rbx),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1222 <main+0xa2>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x800000,%edx
call   1060 <read@plt>
test   %eax,%eax
js     122b <main+0xab>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1210 <main+0x90>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdfa(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf6(%rip),%rdi
jmp    1232 <main+0xb2>
lea    0xdf4(%rip),%rdi
jmp    1232 <main+0xb2>
lea    0xdf0(%rip),%rdi
call   10a0 <perror@plt>
jmp    120b <main+0x8b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"read\00"
@SEEK_CUR = global i32 0
@.str.4 = [20 x i8] c"lseek returned: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 8388608, i32* %8
store i8* null, i8** %9
store i64 0, i64* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %3
br label %55
19: ; preds = %2
%20 = load i32, i32* %8
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
37: ; preds = %27
%38 = load i32, i32* %7
%39 = load i8*, i8** %9
%40 = load i32, i32* %8
%41 = call i32 @read(i32 %38, i8* %39, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
46: ; preds = %37
%47 = load i32, i32* %7
%48 = load i32, i32* @SEEK_CUR
%49 = call i64 @lseek(i32 %47, i32 0, i32 %48)
store i64 %49, i64* %10
%50 = load i64, i64* %10
%51 = trunc i64 %50 to i32
%52 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
store i32 0, i32* %3
br label %55
55: ; preds = %46, %44, %35, %25, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"read\00"
@SEEK_CUR = global i32 0
@.str.4 = [20 x i8] c"lseek returned: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %33
8: ; preds = %2
%9 = tail call i64 @malloc(i32 8388608)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
14: ; preds = %8
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
22: ; preds = %14
%23 = tail call i32 @read(i32 %18, i8* %10, i32 8388608)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %33
27: ; preds = %22
%28 = load i32, i32* @SEEK_CUR
%29 = tail call i64 @lseek(i32 %18, i32 0, i32 %28)
%30 = trunc i64 %29 to i32
%31 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = tail call i32 @close(i32 %18)
br label %33
33: ; preds = %27, %25, %20, %12, %4
%34 = phi i32 [ -1, %4 ], [ -1, %20 ], [ -1, %25 ], [ 0, %27 ], [ -1, %12 ]
ret i32 %34
}