#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 */

/* Variables and functions */
int SEEK_CUR;
int SEEK_END;
int SEEK_SET;
int atoi(char *);
int lseek(int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcasecmp(char *, char *);
void cmd_lseek(int argc, char *argv[]) {
  int fd, offset, whence;
  int ret;
  fd = atoi(argv[1]);
  offset = atoi(argv[2]);
  whence = -1;
  if (strcasecmp(argv[3], "SEEK_SET") == 0)
    whence = SEEK_SET;
  if (strcasecmp(argv[3], "SEEK_CUR") == 0)
    whence = SEEK_CUR;
  if (strcasecmp(argv[3], "SEEK_END") == 0)
    whence = SEEK_END;
  if (whence == -1) {
    printf("whence was not SEEK_SET, SEEK_CUR, or SEEK_END\n");
    return;
  }
  if ((ret = lseek(fd, offset, whence)) == -1)
    perror("lseek");
  else
    printf("lseek: %i\n", ret);
}


x86 assembly (clang, -O0):
<cmd_lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11b0 <cmd_lseek+0x60>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11da <cmd_lseek+0x8a>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1204 <cmd_lseek+0xb4>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1221 <cmd_lseek+0xd1>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125d <cmd_lseek+0x10d>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <lseek@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    124c <cmd_lseek+0xfc>
lea    0xe09(%rip),%rdi
call   1060 <perror@plt>
jmp    125d <cmd_lseek+0x10d>
mov    -0x20(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_lseek>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x18(%rsi),%rbx
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    0x2e4f(%rip),%rcx
neg    %rax
sbb    %ebp,%ebp
or     (%rcx),%ebp
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    11a5 <cmd_lseek+0x45>
mov    0x2e3d(%rip),%rax
mov    (%rax),%ebp
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    11c2 <cmd_lseek+0x62>
mov    0x2e28(%rip),%rax
mov    (%rax),%ebp
cmp    $0xffffffff,%ebp
je     11ff <cmd_lseek+0x9f>
mov    0x10(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     120f <cmd_lseek+0xaf>
lea    0xe26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>
lea    0xe1d(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <puts@plt>
lea    0xdfc(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"SEEK_SET\00"
@SEEK_SET = global i32 0
@.str.1 = [9 x i8] c"SEEK_CUR\00"
@SEEK_CUR = global i32 0
@.str.2 = [9 x i8] c"SEEK_END\00"
@SEEK_END = global i32 0
@.str.3 = [48 x i8] c"whence was not SEEK_SET, SEEK_CUR, or SEEK_END\0A\00"
@.str.4 = [6 x i8] c"lseek\00"
@.str.5 = [11 x i8] c"lseek: %i\0A\00"
define void @cmd_lseek(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %5
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
store i32 -1, i32* %7
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = call i64 @strcasecmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = load i32, i32* @SEEK_SET
store i32 %23, i32* %7
br label %24
24: ; preds = %22, %2
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i64 @strcasecmp(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = load i32, i32* @SEEK_CUR
store i32 %31, i32* %7
br label %32
32: ; preds = %30, %24
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i64 @strcasecmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = load i32, i32* @SEEK_END
store i32 %39, i32* %7
br label %40
40: ; preds = %38, %32
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %56
45: ; preds = %40
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 @lseek(i32 %46, i32 %47, i32 %48)
store i32 %49, i32* %8
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %56
53: ; preds = %45
%54 = load i32, i32* %8
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %43, %53, %51
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"SEEK_SET\00"
@SEEK_SET = global i32 0
@.str.1 = [9 x i8] c"SEEK_CUR\00"
@SEEK_CUR = global i32 0
@.str.2 = [9 x i8] c"SEEK_END\00"
@SEEK_END = global i32 0
@.str.4 = [6 x i8] c"lseek\00"
@.str.5 = [11 x i8] c"lseek: %i\0A\00"
@str = [47 x i8] c"whence was not SEEK_SET, SEEK_CUR, or SEEK_END\00"
define void @cmd_lseek(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 3
%4 = load i8*, i8** %3
%5 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @SEEK_SET
%8 = select i1 %6, i32 %7, i32 -1
%9 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = load i32, i32* @SEEK_CUR
%12 = select i1 %10, i32 %11, i32 %8
%13 = tail call i64 @strcasecmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* @SEEK_END
%16 = select i1 %14, i32 %15, i32 %12
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %33
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = tail call i32 @lseek(i32 %26, i32 %23, i32 %16)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %33
31: ; preds = %20
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %33
33: ; preds = %29, %31, %18
ret void
}