#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_CUR;
int dup(int);
int /*<<< orphan*/ errExit(char *);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int fd1 = open("./test_file", O_RDWR);
  if (fd1 == -1)
    errExit("open");
  int offset = 4;
  if (lseek(fd1, offset, SEEK_CUR) == -1)
    errExit("lseek");
  int fd2 = dup(fd1);
  if (lseek(fd2, 0, SEEK_CUR) == offset)
    printf("offset realy matches\n");
  else
    printf("no\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1194 <main+0x44>
lea    0xe7d(%rip),%rdi
call   1030 <errExit@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11c4 <main+0x74>
lea    0xe52(%rip),%rdi
call   1030 <errExit@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    -0x18(%rbp),%eax
jne    11fc <main+0xac>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
jmp    1208 <main+0xb8>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117c <main+0x2c>
lea    0xe95(%rip),%rdi
call   1040 <errExit@plt>
mov    0x2e5d(%rip),%r14
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x4,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11a3 <main+0x53>
lea    0xe73(%rip),%rdi
call   1040 <errExit@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
mov    (%r14),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0x4,%eax
lea    0xe5a(%rip),%rax
lea    0xe50(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./test_file\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_CUR = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [22 x i8] c"offset realy matches\0A\00"
@.str.4 = [4 x i8] c"no\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @errExit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
store i32 4, i32* %7
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i32, i32* @SEEK_CUR
%19 = call i32 @lseek(i32 %16, i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
%24 = load i32, i32* %6
%25 = call i32 @dup(i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32, i32* @SEEK_CUR
%28 = call i32 @lseek(i32 %26, i32 0, i32 %27)
%29 = load i32, i32* %7
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %35
33: ; preds = %23
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [12 x i8] c"./test_file\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_CUR = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@str = [3 x i8] c"no\00"
@str.5 = [21 x i8] c"offset realy matches\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%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 eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @errExit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @SEEK_CUR
%10 = tail call i32 @lseek(i32 %4, i32 4, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @errExit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = tail call i32 @dup(i32 %4)
%16 = load i32, i32* @SEEK_CUR
%17 = tail call i32 @lseek(i32 %15, i32 0, i32 %16)
%18 = icmp eq i32 %17, 4
%19 = select i1 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0)
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
ret i32 0
}