#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 char *intmax_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc > 2) {
    fprintf(stderr, "Usage: %s [fd]\n", argv[0]);
    return 2;
  }
  int fd = 0;
  if (argc == 2) {
    if (sscanf(argv[1], "%d", &fd) == 0 || fd < 0) {
      fprintf(stderr, "%s: File descriptor must be an integer >=0\n", argv[0]);
      return 2;
    }
  }
  off_t pos = lseek(fd, 0, SEEK_CUR);
  if (pos == (off_t)-1) {
    perror(argv[0]);
    return 1;
  }
  fprintf(stderr, "%jd\n", (intmax_t)pos);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1188 <main+0x48>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    124c <main+0x10c>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f2 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x0,%rax
je     11c5 <main+0x85>
cmpl   $0x0,-0x14(%rbp)
jge    11ed <main+0xad>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    124c <main+0x10c>
jmp    11f2 <main+0xb2>
mov    -0x14(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    122c <main+0xec>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <main+0x10c>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdff(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jl     116a <main+0x2a>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xea2(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%ebp
jmp    11cd <main+0x8d>
mov    %edi,%eax
movl   $0x0,0x4(%rsp)
xor    %edi,%edi
cmp    $0x2,%eax
jne    119d <main+0x5d>
mov    0x8(%rbx),%rdi
lea    0xe8a(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
test   %rax,%rax
je     11d6 <main+0x96>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     11d6 <main+0x96>
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     11ee <main+0xae>
mov    0x2e1c(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7a(%rip),%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2a(%rip),%rsi
jmp    115e <main+0x1e>
mov    (%rbx),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebp
jmp    11cd <main+0x8d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s [fd]\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"%s: File descriptor must be an integer >=0\0A\00"
@SEEK_CUR = global i32 0
@.str.3 = [5 x i8] c"%jd\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 2, i32* %3
br label %51
16: ; preds = %2
store i32 0, i32* %6
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %19
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25, %19
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 2, i32* %3
br label %51
34: ; preds = %25
br label %35
35: ; preds = %34, %16
%36 = load i32, i32* %6
%37 = load i32, i32* @SEEK_CUR
%38 = call i64 @lseek(i32 %36, i32 0, i32 %37)
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = icmp eq i64 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @perror(i8* %44)
store i32 1, i32* %3
br label %51
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = load i64, i64* %7
%49 = inttoptr i64 %48 to i8*
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %46, %41, %28, %10
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s [fd]\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"%s: File descriptor must be an integer >=0\0A\00"
@SEEK_CUR = global i32 0
@.str.3 = [5 x i8] c"%jd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %38
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %36
24: ; preds = %12, %9
%25 = phi i32 [ %17, %12 ], [ 0, %9 ]
%26 = load i32, i32* @SEEK_CUR
%27 = call i64 @lseek(i32 %25, i32 0, i32 %26)
%28 = icmp eq i64 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %1
%31 = call i32 @perror(i8* %30)
br label %36
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = inttoptr i64 %27 to i8*
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %29, %32, %20
%37 = phi i32 [ 2, %20 ], [ 1, %29 ], [ 0, %32 ]
br label %38
38: ; preds = %36, %5
%39 = phi i32 [ 2, %5 ], [ %37, %36 ]
ret i32 %39
}