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

/* Variables and functions */
scalar_t__ lseek(int, scalar_t__, int);
int /*<<< orphan*/ print_on_level(int, char *, char *, int, long, int);
int lseek_safe(int fd, off_t offset, int whence) {
  off_t new;
  new = lseek(fd, offset, whence);
  if (new == (off_t)-1) {
    print_on_level((1),
                   "Error (%s:%d): "
                   "Failed to seek %li as %d\n"
                   ": %m\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/cyrillos/cpt2/refs/heads/"
                   "master/src/include/io.h",
                   58, (long)offset, whence);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<lseek_safe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1181 <lseek_safe+0x61>
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    $0x1,%edi
lea    0xe9c(%rip),%rsi
lea    0xec3(%rip),%rdx
mov    $0x3a,%ecx
call   1040 <print_on_level@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <lseek_safe+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lseek_safe>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
call   1030 <lseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0xffffffffffffffff,%rcx
jne    1160 <lseek_safe+0x40>
lea    0xec1(%rip),%rsi
lea    0xee8(%rip),%rdx
mov    $0x1,%edi
mov    $0x3a,%ecx
mov    %rbx,%r8
mov    %ebp,%r9d
call   1040 <print_on_level@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Error (%s:%d): Failed to seek %li as %d\0A: %m\0A\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cyrillos/cpt2/refs/heads/master/src/include/io.h\00"
define i32 @lseek_safe(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i64, i64* %6
%11 = load i32, i32* %7
%12 = call i64 @lseek(i32 %9, i64 %10, i32 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i64, i64* %6
%17 = load i32, i32* %7
%18 = call i32 @print_on_level(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 58, i64 %16, i32 %17)
store i32 -1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %15
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [46 x i8] c"Error (%s:%d): Failed to seek %li as %d\0A: %m\0A\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cyrillos/cpt2/refs/heads/master/src/include/io.h\00"
define i32 @lseek_safe(i32 %0, i64 %1, i32 %2) {
%4 = tail call i64 @lseek(i32 %0, i64 %1, i32 %2)
%5 = icmp eq i64 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @print_on_level(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 58, i64 %1, i32 %2)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ -1, %6 ], [ 0, %3 ]
ret i32 %9
}