#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 /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
char getchar();
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void m_seek(int fd) {
  char seek_base;
  int offset;
  printf("syntax:_N N is the offset number\n");
  printf("       sN---seek from the begin\n");
  printf("       cN---seek from the current\n");
  printf("       eN---seek from the end\n");
  printf("input where to seek pls:");
  seek_base = getchar();
  scanf("%d", &offset);
  getchar();
  switch (seek_base) {
  case 's':
    lseek(fd, offset, SEEK_SET);
    break;
  case 'c':
    lseek(fd, offset, SEEK_CUR);
    break;
  case 'e':
    lseek(fd, offset, SEEK_END);
    break;
  default:
    printf("Check you input!\n");
  }
}


x86 assembly (clang, -O0):
<m_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
call   1030 <printf@plt>
lea    0xef0(%rip),%rdi
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %al,-0x11(%rbp)
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
lea    0xf03(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x11(%rbp),%al
call   1050 <getchar@plt>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x63,%eax
je     11fc <m_seek+0xbc>
jmp    11c1 <m_seek+0x81>
mov    -0x10(%rbp),%eax
sub    $0x65,%eax
je     1215 <m_seek+0xd5>
jmp    11d2 <m_seek+0x92>
mov    -0x10(%rbp),%eax
sub    $0x73,%eax
jne    122e <m_seek+0xee>
jmp    11e3 <m_seek+0xa3>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
jmp    123a <m_seek+0xfa>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
jmp    123a <m_seek+0xfa>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
jmp    123a <m_seek+0xfa>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_seek>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
lea    0xe78(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
movsbl %bl,%eax
cmp    $0x63,%eax
je     11d1 <m_seek+0x81>
cmp    $0x65,%eax
je     11de <m_seek+0x8e>
cmp    $0x73,%eax
jne    11f4 <m_seek+0xa4>
mov    0x4(%rsp),%esi
mov    0x2e01(%rip),%rax
jmp    11e9 <m_seek+0x99>
mov    0x4(%rsp),%esi
mov    0x2e04(%rip),%rax
jmp    11e9 <m_seek+0x99>
mov    0x4(%rsp),%esi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <lseek@plt>
jmp    1200 <m_seek+0xb0>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"syntax:_N N is the offset number\0A\00"
@.str.1 = [33 x i8] c" sN---seek from the begin\0A\00"
@.str.2 = [35 x i8] c" cN---seek from the current\0A\00"
@.str.3 = [31 x i8] c" eN---seek from the end\0A\00"
@.str.4 = [25 x i8] c"input where to seek pls:\00"
@.str.5 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@.str.6 = [18 x i8] c"Check you input!\0A\00"
define void @m_seek(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %3
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%12 = call signext i8 (...) @getchar()
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
switch i32 %14, label %30 [
i32 115, label %15
i32 99, label %20
i32 101, label %25
]
15: ; preds = %1
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @lseek(i32 %16, i32 %17, i32 %18)
br label %32
20: ; preds = %1
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = load i32, i32* @SEEK_CUR
%24 = call i32 @lseek(i32 %21, i32 %22, i32 %23)
br label %32
25: ; preds = %1
%26 = load i32, i32* %2
%27 = load i32, i32* %4
%28 = load i32, i32* @SEEK_END
%29 = call i32 @lseek(i32 %26, i32 %27, i32 %28)
br label %32
30: ; preds = %1
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %25, %20, %15
ret void
}

LLVM IR (-O2):
@.str.4 = [25 x i8] c"input where to seek pls:\00"
@.str.5 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@str = [33 x i8] c"syntax:_N N is the offset number\00"
@str.7 = [32 x i8] c" sN---seek from the begin\00"
@str.8 = [34 x i8] c" cN---seek from the current\00"
@str.9 = [30 x i8] c" eN---seek from the end\00"
@str.10 = [17 x i8] c"Check you input!\00"
define void @m_seek(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call signext i8 (...) @getchar()
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%11 = call signext i8 (...) @getchar()
%12 = sext i8 %9 to i32
switch i32 %12, label %25 [
i32 115, label %13
i32 99, label %17
i32 101, label %21
]
13: ; preds = %1
%14 = load i32, i32* %2
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %0, i32 %14, i32 %15)
br label %27
17: ; preds = %1
%18 = load i32, i32* %2
%19 = load i32, i32* @SEEK_CUR
%20 = call i32 @lseek(i32 %0, i32 %18, i32 %19)
br label %27
21: ; preds = %1
%22 = load i32, i32* %2
%23 = load i32, i32* @SEEK_END
%24 = call i32 @lseek(i32 %0, i32 %22, i32 %23)
br label %27
25: ; preds = %1
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
br label %27
27: ; preds = %25, %21, %17, %13
ret void
}