#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_CUR;
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int fd1, fd2;
  fd1 = open("/etc/passwd", O_RDONLY);
  fd2 = open("/etc/passwd", O_RDONLY);
  printf("first: %d second: %d\n", lseek(fd1, 0, SEEK_CUR),
         lseek(fd2, 0, SEEK_CUR));
  lseek(fd1, 20, SEEK_SET);
  printf("first: %d second: %d\n", lseek(fd1, 0, SEEK_CUR),
         lseek(fd2, 0, SEEK_CUR));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea1(%rip),%r14
mov    (%r14),%esi
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%r15d
mov    0x2e80(%rip),%r12
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
mov    (%r12),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
lea    0xe80(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x14,%esi
call   1040 <lseek@plt>
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
mov    (%r12),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"first: %d second: %d\0A\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* @SEEK_CUR
%10 = call i32 @lseek(i32 %8, i32 0, i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @SEEK_CUR
%13 = call i32 @lseek(i32 %11, i32 0, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %15, i32 20, i32 %16)
%18 = load i32, i32* %2
%19 = load i32, i32* @SEEK_CUR
%20 = call i32 @lseek(i32 %18, i32 0, i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* @SEEK_CUR
%23 = call i32 @lseek(i32 %21, i32 0, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"first: %d second: %d\0A\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @SEEK_CUR
%6 = tail call i32 @lseek(i32 %2, i32 0, i32 %5)
%7 = load i32, i32* @SEEK_CUR
%8 = tail call i32 @lseek(i32 %4, i32 0, i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %8)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %2, i32 20, i32 %10)
%12 = load i32, i32* @SEEK_CUR
%13 = tail call i32 @lseek(i32 %2, i32 0, i32 %12)
%14 = load i32, i32* @SEEK_CUR
%15 = tail call i32 @lseek(i32 %4, i32 0, i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
ret i32 0
}