#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_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int fd = open("file1", O_RDONLY);
  if (fd == -1) {
    puts("open()");
    return 0;
  }
  printf("%ld\n", lseek(fd, 0, SEEK_END));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1199 <main+0x49>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <main+0x79>
mov    -0x8(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%esi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1196 <main+0x46>
mov    %eax,%ebx
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    11a2 <main+0x52>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %16
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @SEEK_END
%12 = call i32 @lseek(i32 %10, i32 0, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
store i32 0, i32* %1
br label %16
16: ; preds = %9, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [6 x i8] c"file1\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %11
6: ; preds = %0
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @lseek(i32 %2, i32 0, i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32 @close(i32 %2)
br label %11
11: ; preds = %6, %4
ret i32 0
}