#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 */
int EOF;
int SEEK_SET;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ lseek(int, scalar_t__, int);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  int fd;
  long long scan_offset = 0;
  off_t offset = 0;
  int whence = SEEK_SET;
  int errsv;
  int rv;
  if (argc == 1) {
    fprintf(stderr, "usage: seekfd fd [offset [whence]]\n");
    exit(1);
  }
  if (argc >= 2) {
    if (sscanf(argv[1], "%d", &fd) == EOF) {
      errsv = errno;
      fprintf(stderr, "%s: %s\n", argv[0], strerror(errsv));
      exit(1);
    }
  }
  if (argc >= 3) {
    rv = sscanf(argv[2], "%lld", &scan_offset);
    if (rv == EOF) {
      errsv = errno;
      fprintf(stderr, "%s: %s\n", argv[0], strerror(errsv));
      exit(1);
    }
    offset = (off_t)scan_offset;
  }
  if (argc >= 4) {
    if (sscanf(argv[3], "%d", &whence) == EOF) {
      errsv = errno;
      fprintf(stderr, "%s: %s\n", argv[0], strerror(errsv));
      exit(1);
    }
  }
  if (lseek(fd, offset, whence) == (off_t)-1) {
    errsv = errno;
    fprintf(stderr, "%s: %s\n", argv[0], strerror(errsv));
    exit(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b0 <main+0x60>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jl     1235 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%eax
jne    1230 <main+0xe0>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1235 <main+0xe5>
cmpl   $0x3,-0x8(%rbp)
jl     12c3 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde1(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d82(%rip),%rcx
cmp    (%rcx),%eax
jne    12bb <main+0x16b>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     1348 <main+0x1f8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd48(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%eax
jne    1343 <main+0x1f3>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1348 <main+0x1f8>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
jne    13ae <main+0x25e>
mov    0x2c68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xc8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,(%rsp)
cmp    $0x1,%edi
je     1223 <main+0xd3>
mov    %rsi,%r14
jle    11fd <main+0xad>
mov    %edi,%ebx
mov    0x8(%r14),%rdi
lea    0xe98(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x2e49(%rip),%r12
cmp    (%r12),%eax
je     127e <main+0x12e>
cmp    $0x3,%ebx
jb     11fd <main+0xad>
mov    0x10(%r14),%rdi
lea    0xe76(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    (%r12),%eax
je     127e <main+0x12e>
mov    0x8(%rsp),%r15
cmp    $0x4,%ebx
jb     1200 <main+0xb0>
mov    0x18(%r14),%rdi
lea    0xe40(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    (%r12),%eax
je     127e <main+0x12e>
mov    (%rsp),%ebp
jmp    1200 <main+0xb0>
xor    %r15d,%r15d
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     1244 <main+0xf4>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
call   1070 <strerror@plt>
lea    0xdc2(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
call   1070 <strerror@plt>
lea    0xd88(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"usage: seekfd fd [offset [whence]]\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i32 0
@errno = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [5 x i8] c"%lld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i64 0, i64* %8
%12 = load i32, i32* @SEEK_SET
store i32 %12, i32* %9
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 2
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %22
%30 = load i32, i32* @errno
store i32 %30, i32* %10
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i32, i32* %10
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %22
br label %40
40: ; preds = %39, %19
%41 = load i32, i32* %4
%42 = icmp sge i32 %41, 3
br i1 %42, label %43, label %63
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 (i8*, i8*, ...) @sscanf(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64* %7)
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %61
51: ; preds = %43
%52 = load i32, i32* @errno
store i32 %52, i32* %10
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = load i32, i32* %10
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %43
%62 = load i64, i64* %7
store i64 %62, i64* %8
br label %63
63: ; preds = %61, %40
%64 = load i32, i32* %4
%65 = icmp sge i32 %64, 4
br i1 %65, label %66, label %84
66: ; preds = %63
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 3
%69 = load i8*, i8** %68
%70 = call i32 (i8*, i8*, ...) @sscanf(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%71 = load i32, i32* @EOF
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %83
73: ; preds = %66
%74 = load i32, i32* @errno
store i32 %74, i32* %10
%75 = load i32, i32* @stderr
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 0
%78 = load i8*, i8** %77
%79 = load i32, i32* %10
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %78, i8* %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %66
br label %84
84: ; preds = %83, %63
%85 = load i32, i32* %6
%86 = load i64, i64* %8
%87 = load i32, i32* %9
%88 = call i64 @lseek(i32 %85, i64 %86, i32 %87)
%89 = icmp eq i64 %88, -1
br i1 %89, label %90, label %100
90: ; preds = %84
%91 = load i32, i32* @errno
store i32 %91, i32* %10
%92 = load i32, i32* @stderr
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 0
%95 = load i8*, i8** %94
%96 = load i32, i32* %10
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %95, i8* %97)
%99 = call i32 @exit(i32 2)
unreachable
100: ; preds = %84
ret i32 0
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"usage: seekfd fd [offset [whence]]\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i32 0
@errno = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [5 x i8] c"%lld\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @SEEK_SET
store i32 %9, i32* %5
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %63
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = call i8* @strerror(i32 %24)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = icmp ugt i32 %0, 2
br i1 %31, label %32, label %63
32: ; preds = %30
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = call i32 (i8*, i8*, ...) @sscanf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i32, i32* @errno
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %1
%42 = call i8* @strerror(i32 %39)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = load i64, i64* %4
%47 = icmp ugt i32 %0, 3
br i1 %47, label %48, label %63
48: ; preds = %45
%49 = getelementptr inbounds i8*, i8** %1, i64 3
%50 = load i8*, i8** %49
%51 = call i32 (i8*, i8*, ...) @sscanf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %56, label %54
54: ; preds = %48
%55 = load i32, i32* %5
br label %63
56: ; preds = %48
%57 = load i32, i32* @errno
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %1
%60 = call i8* @strerror(i32 %57)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %59, i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54, %15, %30, %45
%64 = phi i32 [ %55, %54 ], [ %9, %45 ], [ %9, %30 ], [ %9, %15 ]
%65 = phi i64 [ %46, %54 ], [ %46, %45 ], [ 0, %30 ], [ 0, %15 ]
%66 = load i32, i32* %3
%67 = call i64 @lseek(i32 %66, i64 %65, i32 %64)
%68 = icmp eq i64 %67, -1
br i1 %68, label %69, label %76
69: ; preds = %63
%70 = load i32, i32* @errno
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %1
%73 = call i8* @strerror(i32 %70)
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %72, i8* %73)
%75 = call i32 @exit(i32 2)
unreachable
76: ; preds = %63
ret i32 0
}