#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
#define SEEK_CUR 130
#define SEEK_END 129
#define SEEK_SET 128
int fseek(int /*<<< orphan*/ *, long, int);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getnonullfile(int);
int /*<<< orphan*/ luaL_argerror(int, char *);
int luaL_findstring(int /*<<< orphan*/, char **);
int /*<<< orphan*/ luaL_opt_lstr(int, char *, int /*<<< orphan*/ *);
scalar_t__ luaL_opt_number(int, int /*<<< orphan*/);
int /*<<< orphan*/ lua_pushnumber(int /*<<< orphan*/);
int /*<<< orphan*/ pushresult(int /*<<< orphan*/);
void io_seek(void) {
  static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  static char *modenames[] = {"set", "cur", "end", NULL};
  FILE *f = getnonullfile(2);
  int op = luaL_findstring((luaL_opt_lstr((2 + 1), ("cur"), NULL)), modenames);
  long offset = ((long)luaL_opt_number(2 + 2, 0));
  if (!(op != -1))
    luaL_argerror(2 + 1, "invalid mode");
  op = fseek(f, offset, mode[op]);
  if (op)
    pushresult(0);
  else
    lua_pushnumber(ftell(f));
}


x86 assembly (clang, -O0):
<io_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x2,%edi
call   1060 <getnonullfile@plt>
mov    %rax,-0x8(%rbp)
mov    $0x3,%edi
lea    0xe52(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <luaL_opt_lstr@plt>
mov    %eax,%edi
lea    0x2ebc(%rip),%rsi
call   1070 <luaL_findstring@plt>
mov    %eax,-0xc(%rbp)
mov    $0x4,%edi
xor    %esi,%esi
call   1030 <luaL_opt_number@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11f7 <io_seek+0x67>
mov    $0x3,%edi
lea    0xe1a(%rip),%rsi
call   1040 <luaL_argerror@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rcx
lea    0x2e66(%rip),%rax
mov    (%rax,%rcx,4),%edx
call   10b0 <fseek@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     122b <io_seek+0x9b>
xor    %edi,%edi
call   1050 <pushresult@plt>
jmp    123b <io_seek+0xab>
mov    -0x8(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,%edi
call   10a0 <lua_pushnumber@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_seek>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%edi
call   1060 <getnonullfile@plt>
mov    %rax,%r14
lea    0xe68(%rip),%rsi
mov    $0x3,%edi
xor    %edx,%edx
call   1080 <luaL_opt_lstr@plt>
lea    0x2eb5(%rip),%rsi
mov    %eax,%edi
call   1070 <luaL_findstring@plt>
mov    %eax,%ebp
mov    $0x4,%edi
xor    %esi,%esi
call   1030 <luaL_opt_number@plt>
mov    %rax,%rbx
cmp    $0xffffffff,%ebp
jne    11e9 <io_seek+0x59>
lea    0xe39(%rip),%rsi
mov    $0x3,%edi
call   1040 <luaL_argerror@plt>
movslq %ebp,%rax
lea    0xe0d(%rip),%rcx
mov    (%rcx,%rax,4),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <fseek@plt>
test   %eax,%eax
je     1210 <io_seek+0x80>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <pushresult@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <lua_pushnumber@plt>

LLVM IR (-O0):
@io_seek.mode = internal global [3 x i32] [i32 128, i32 130, i32 129]
@io_seek.modenames = internal global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"set\00"
@.str.1 = [4 x i8] c"cur\00"
@.str.2 = [4 x i8] c"end\00"
@.str.3 = [13 x i8] c"invalid mode\00"
define void @io_seek() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i64
%4 = call i32* @getnonullfile(i32 2)
store i32* %4, i32** %1
%5 = call i32 @luaL_opt_lstr(i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
%6 = call i32 @luaL_findstring(i32 %5, i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @io_seek.modenames, i64 0, i64 0))
store i32 %6, i32* %2
%7 = call i64 @luaL_opt_number(i32 4, i32 0)
store i64 %7, i64* %3
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @luaL_argerror(i32 3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = load i32*, i32** %1
%14 = load i64, i64* %3
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i32], [3 x i32]* @io_seek.mode, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @fseek(i32* %13, i64 %14, i32 %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @pushresult(i32 0)
br label %28
24: ; preds = %12
%25 = load i32*, i32** %1
%26 = call i32 @ftell(i32* %25)
%27 = call i32 @lua_pushnumber(i32 %26)
br label %28
28: ; preds = %24, %22
ret void
}

LLVM IR (-O2):
@io_seek.mode = internal unnamed_addr constant [3 x i32] [i32 128, i32 130, i32 129]
@io_seek.modenames = internal global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"set\00"
@.str.1 = [4 x i8] c"cur\00"
@.str.2 = [4 x i8] c"end\00"
@.str.3 = [13 x i8] c"invalid mode\00"
define void @io_seek() {
%1 = tail call i32* @getnonullfile(i32 2)
%2 = tail call i32 @luaL_opt_lstr(i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
%3 = tail call i32 @luaL_findstring(i32 %2, i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @io_seek.modenames, i64 0, i64 0))
%4 = tail call i64 @luaL_opt_number(i32 4, i32 0)
%5 = icmp eq i32 %3, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @luaL_argerror(i32 3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds [3 x i32], [3 x i32]* @io_seek.mode, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @fseek(i32* %1, i64 %4, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 @pushresult(i32 0)
br label %19
16: ; preds = %8
%17 = tail call i32 @ftell(i32* %1)
%18 = tail call i32 @lua_pushnumber(i32 %17)
br label %19
19: ; preds = %16, %14
ret void
}