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

/* Variables and functions */
int check_offsets(int *, size_t, int);
int lseek(int, int, int);
int /*<<< orphan*/ printf(char *, int, long long, int /*<<< orphan*/,
                          long long);
int /*<<< orphan*/ whence_to_string(int);
int lseek_and_check(int fds[], size_t count, int selected, off_t offset,
                    int whence) {
  off_t new_offset;
  if ((new_offset = lseek(fds[selected], offset, whence)) == -1) {
    return -1;
  }
  printf("lseek(fds[%d], %lld, %s) = %lld\n", selected, (long long)offset,
         whence_to_string(whence), (long long)new_offset);
  return check_offsets(fds, count, new_offset);
}


x86 assembly (clang, -O0):
<lseek_and_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <lseek@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    1188 <lseek_and_check+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <lseek_and_check+0x8a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <whence_to_string@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
movslq -0x28(%rbp),%r8
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1060 <check_offsets@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lseek_and_check>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
movslq %edx,%rax
mov    (%rdi,%rax,4),%edi
mov    %ecx,%esi
mov    %r8d,%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11ad <lseek_and_check+0x6d>
mov    %eax,%ebx
movslq %ebp,%rbp
mov    %r13d,%edi
call   1050 <whence_to_string@plt>
movslq %ebx,%r8
lea    0xe7b(%rip),%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <check_offsets@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"lseek(fds[%d], %lld, %s) = %lld\0A\00"
define i32 @lseek_and_check(i32* %0, i64 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %7
store i64 %1, i64* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i32*, i32** %7
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* %10
%19 = load i32, i32* %11
%20 = call i32 @lseek(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %12
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %5
store i32 -1, i32* %6
br label %36
23: ; preds = %5
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = load i32, i32* %11
%28 = call i32 @whence_to_string(i32 %27)
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %24, i64 %26, i32 %28, i64 %30)
%32 = load i32*, i32** %7
%33 = load i64, i64* %8
%34 = load i32, i32* %12
%35 = call i32 @check_offsets(i32* %32, i64 %33, i32 %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %23, %22
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
@.str = [33 x i8] c"lseek(fds[%d], %lld, %s) = %lld\0A\00"
define i32 @lseek_and_check(i32* %0, i64 %1, i32 %2, i32 %3, i32 %4) {
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @lseek(i32 %8, i32 %3, i32 %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = sext i32 %3 to i64
%13 = tail call i32 @whence_to_string(i32 %4)
%14 = sext i32 %9 to i64
%15 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %2, i64 %12, i32 %13, i64 %14)
%16 = tail call i32 @check_offsets(i32* %0, i64 %1, i32 %9)
br label %17
17: ; preds = %5, %11
%18 = phi i32 [ %16, %11 ], [ -1, %5 ]
ret i32 %18
}