#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;
typedef int intmax_t;

/* Variables and functions */
int EOF;
int SEEK_CUR;
int SEEK_END;
int SEEK_SET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lseek(int, scalar_t__, int);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int relative = 0;
  int fd = 0;
  int nextarg = 1;
  if (argc < 2) {
  arg_error:
    fprintf(stderr, "Usage: %s [-r] [fd] offset\n", argv[0]);
    return 2;
  }
  if (!strcmp(argv[1], "-r")) {
    relative = 1;
    nextarg = 2;
  }
  int remaining_args = argc - nextarg;
  if (remaining_args < 1 || remaining_args > 2)
    goto arg_error;
  int scanf_result;
  if (remaining_args == 2) {
    scanf_result = sscanf(argv[nextarg], "%d", &fd);
    if (scanf_result == 0 || scanf_result == EOF)
      goto arg_error;
  }
  intmax_t intmax;
  scanf_result = sscanf(argv[argc - 1], "%jd", &intmax);
  if (scanf_result == 0 || scanf_result == EOF)
    goto arg_error;
  int whence;
  if (relative)
    whence = SEEK_CUR;
  else
    whence = (argv[argc - 1][0] == '-') ? SEEK_END : SEEK_SET;
  if (lseek(fd, (off_t)intmax, whence) == (off_t)-1) {
    perror(argv[0]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b2 <main+0x62>
jmp    118a <main+0x3a>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1326 <main+0x1d6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11dd <main+0x8d>
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jl     11fa <main+0xaa>
cmpl   $0x2,-0x20(%rbp)
jle    11ff <main+0xaf>
jmp    118a <main+0x3a>
cmpl   $0x2,-0x20(%rbp)
jne    124e <main+0xfe>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe03(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1244 <main+0xf4>
mov    -0x24(%rbp),%eax
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%eax
jne    1249 <main+0xf9>
jmp    118a <main+0x3a>
jmp    124e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdbc(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     128e <main+0x13e>
mov    -0x24(%rbp),%eax
mov    0x2d52(%rip),%rcx
cmp    (%rcx),%eax
jne    1293 <main+0x143>
jmp    118a <main+0x3a>
cmpl   $0x0,-0x14(%rbp)
je     12ae <main+0x15e>
mov    0x2d3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ee <main+0x19e>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12dc <main+0x18c>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    12e8 <main+0x198>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
movslq -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
jne    131f <main+0x1cf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1d6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movl   $0x0,0x8(%rsp)
cmp    $0x1,%edi
jle    1193 <main+0x43>
mov    %edi,%ebx
mov    0x8(%r14),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
mov    $0x1,%eax
adc    $0x0,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
lea    -0x3(%rcx),%edx
cmp    $0xfffffffe,%edx
jae    11b9 <main+0x69>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x2,%ecx
jne    11e4 <main+0x94>
mov    %eax,%eax
mov    (%r14,%rax,8),%rdi
lea    0xe54(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
je     1193 <main+0x43>
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     1193 <main+0x43>
add    $0xffffffff,%ebx
mov    (%r14,%rbx,8),%rdi
lea    0xe30(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
je     1193 <main+0x43>
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
je     1193 <main+0x43>
test   %ebp,%ebp
je     1221 <main+0xd1>
mov    (%r14,%rbx,8),%rax
cmpb   $0x2d,(%rax)
jne    122a <main+0xda>
mov    0x2dc9(%rip),%rax
jmp    1231 <main+0xe1>
mov    0x2db8(%rip),%rax
jmp    1231 <main+0xe1>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
mov    0x8(%rsp),%edi
movslq 0xc(%rsp),%rsi
call   1030 <lseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0xffffffffffffffff,%rcx
jne    11b0 <main+0x60>
mov    (%r14),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11b0 <main+0x60>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s [-r] [fd] offset\0A\00"
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.3 = [4 x i8] c"%jd\00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
br label %16
16: ; preds = %71, %55, %38, %15
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 2, i32* %3
br label %107
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 1, i32* %6
store i32 2, i32* %8
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %4
%31 = load i32, i32* %8
%32 = sub nsw i32 %30, %31
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 1
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = load i32, i32* %9
%37 = icmp sgt i32 %36, 2
br i1 %37, label %38, label %39
38: ; preds = %35, %29
br label %16
39: ; preds = %35
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %42
%52 = load i32, i32* %10
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %51, %42
br label %16
56: ; preds = %51
br label %57
57: ; preds = %56, %39
%58 = load i8**, i8*** %5
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %58, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %11)
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = icmp eq i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %57
%68 = load i32, i32* %10
%69 = load i32, i32* @EOF
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %72
71: ; preds = %67, %57
br label %16
72: ; preds = %67
%73 = load i32, i32* %6
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = load i32, i32* @SEEK_CUR
store i32 %76, i32* %12
br label %94
77: ; preds = %72
%78 = load i8**, i8*** %5
%79 = load i32, i32* %4
%80 = sub nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %78, i64 %81
%83 = load i8*, i8** %82
%84 = getelementptr inbounds i8, i8* %83, i64 0
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 45
br i1 %87, label %88, label %90
88: ; preds = %77
%89 = load i32, i32* @SEEK_END
br label %92
90: ; preds = %77
%91 = load i32, i32* @SEEK_SET
br label %92
92: ; preds = %90, %88
%93 = phi i32 [ %89, %88 ], [ %91, %90 ]
store i32 %93, i32* %12
br label %94
94: ; preds = %92, %75
%95 = load i32, i32* %7
%96 = load i32, i32* %11
%97 = sext i32 %96 to i64
%98 = load i32, i32* %12
%99 = call i64 @lseek(i32 %95, i64 %97, i32 %98)
%100 = icmp eq i64 %99, -1
br i1 %100, label %101, label %106
101: ; preds = %94
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 0
%104 = load i8*, i8** %103
%105 = call i32 @perror(i8* %104)
store i32 1, i32* %3
br label %107
106: ; preds = %94
store i32 0, i32* %3
br label %107
107: ; preds = %106, %101, %16
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s [-r] [fd] offset\0A\00"
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.3 = [4 x i8] c"%jd\00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %31, %22, %11, %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %61
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 2, i32 1
%17 = sub nuw nsw i32 %0, %16
%18 = add nsw i32 %17, -3
%19 = icmp ult i32 %18, -2
br i1 %19, label %7, label %20
20: ; preds = %11
%21 = icmp eq i32 %17, 2
br i1 %21, label %22, label %31
22: ; preds = %20
%23 = zext i32 %16 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %26, %28
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %7, label %31
31: ; preds = %22, %20
%32 = add nsw i32 %0, -1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%37 = icmp eq i32 %36, 0
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %36, %38
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %7, label %41
41: ; preds = %31
br i1 %15, label %42, label %44
42: ; preds = %41
%43 = load i32, i32* @SEEK_CUR
br label %51
44: ; preds = %41
%45 = load i8*, i8** %34
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 45
%48 = load i32, i32* @SEEK_END
%49 = load i32, i32* @SEEK_SET
%50 = select i1 %47, i32 %48, i32 %49
br label %51
51: ; preds = %44, %42
%52 = phi i32 [ %43, %42 ], [ %50, %44 ]
%53 = load i32, i32* %3
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = call i64 @lseek(i32 %53, i64 %55, i32 %52)
%57 = icmp eq i64 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = load i8*, i8** %1
%60 = call i32 @perror(i8* %59)
br label %61
61: ; preds = %51, %58, %7
%62 = phi i32 [ 2, %7 ], [ 1, %58 ], [ 0, %51 ]
ret i32 %62
}