#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
long lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long);
int seek_byte(int fd, int byte) {
  long int pos, cur_pos;
  pos = 0;
  pos = (long int)lseek(fd, 0, SEEK_CUR);
  printf("Current seek position == %ld\n", pos);
  pos = lseek(fd, byte, SEEK_SET);
  cur_pos = lseek(fd, 0, SEEK_CUR);
  printf("Now seek position == %ld\n\n", cur_pos);
  return cur_pos;
}


x86 assembly (clang, -O0):
<seek_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seek_byte>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2eb9(%rip),%r14
mov    (%r14),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
lea    0xec0(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <lseek@plt>
mov    (%r14),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@.str = [30 x i8] c"Current seek position == %ld\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [27 x i8] c"Now seek position == %ld\0A\0A\00"
define i32 @seek_byte(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i64 0, i64* %5
%7 = load i32, i32* %3
%8 = load i32, i32* @SEEK_CUR
%9 = call i64 @lseek(i32 %7, i32 0, i32 %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @lseek(i32 %12, i32 %13, i32 %14)
store i64 %15, i64* %5
%16 = load i32, i32* %3
%17 = load i32, i32* @SEEK_CUR
%18 = call i64 @lseek(i32 %16, i32 0, i32 %17)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = load i64, i64* %6
%22 = trunc i64 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@.str = [30 x i8] c"Current seek position == %ld\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [27 x i8] c"Now seek position == %ld\0A\0A\00"
define i32 @seek_byte(i32 %0, i32 %1) {
%3 = load i32, i32* @SEEK_CUR
%4 = tail call i64 @lseek(i32 %0, i32 0, i32 %3)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %0, i32 %1, i32 %6)
%8 = load i32, i32* @SEEK_CUR
%9 = tail call i64 @lseek(i32 %0, i32 0, i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %9)
%11 = trunc i64 %9 to i32
ret i32 %11
}