#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 */
int /*<<< orphan*/ *getfileparam(char *, int *);
int /*<<< orphan*/ luaL_buffer();
int luaL_findstring(char *, char **);
long luaL_getsize();
char *luaL_opt_lstr(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ luaL_resetbuffer();
int /*<<< orphan*/ lua_pushlstring(int /*<<< orphan*/, long);
int /*<<< orphan*/ read_file(int /*<<< orphan*/ *);
int read_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ read_number(int /*<<< orphan*/ *);
int read_pattern(int /*<<< orphan*/ *, char *);
void io_read(void) {
  static char *options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
  int arg = 2;
  FILE *f = getfileparam("_INPUT", &arg);
  char *p = (luaL_opt_lstr((arg++), ("*l"), NULL));
  do {
    long l;
    int success;
    luaL_resetbuffer();
    switch (luaL_findstring(p, options)) {
    case 0:
      if (!read_number(f))
        return;
      continue;
    case 1:
      success = read_line(f);
      break;
    case 2:
    case 3:
      read_file(f);
      success = 1;
      break;
    case 4:
      success = read_pattern(f, "{%s*}%S+");
      break;
    default:
      success = read_pattern(f, p);
    }
    l = luaL_getsize();
    if (!success && l == 0)
      return;
    lua_pushlstring(luaL_buffer(), l);
  } while ((p = (luaL_opt_lstr((arg++), (NULL), NULL))) != NULL);
}


x86 assembly (clang, -O0):
<io_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x2,-0x4(%rbp)
lea    0xe5d(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1090 <getfileparam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xe32(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <luaL_opt_lstr@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
call   10c0 <luaL_resetbuffer@plt>
mov    -0x18(%rbp),%rdi
lea    0x2e7c(%rip),%rsi
call   1060 <luaL_findstring@plt>
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x4,%eax
ja     1286 <io_read+0xd6>
mov    -0x30(%rbp),%rax
lea    0xddd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   10d0 <read_number@plt>
cmp    $0x0,%eax
jne    1243 <io_read+0x93>
jmp    12f2 <io_read+0x142>
jmp    12cd <io_read+0x11d>
mov    -0x10(%rbp),%rdi
call   10b0 <read_line@plt>
mov    %eax,-0x24(%rbp)
jmp    1296 <io_read+0xe6>
mov    -0x10(%rbp),%rdi
call   1080 <read_file@plt>
movl   $0x1,-0x24(%rbp)
jmp    1296 <io_read+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1050 <read_pattern@plt>
mov    %eax,-0x24(%rbp)
jmp    1296 <io_read+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <read_pattern@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <luaL_getsize@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12bb <io_read+0x10b>
cmpq   $0x0,-0x20(%rbp)
jne    12bb <io_read+0x10b>
jmp    12f2 <io_read+0x142>
mov    $0x0,%al
call   1030 <luaL_buffer@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
call   10a0 <lua_pushlstring@plt>
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1070 <luaL_opt_lstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f2 <io_read+0x42>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x2,0x4(%rsp)
lea    0xe59(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <getfileparam@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0x4(%rsp)
lea    0xe2e(%rip),%rsi
xor    %edx,%edx
call   1070 <luaL_opt_lstr@plt>
mov    %rax,%rbx
lea    0x2e86(%rip),%r14
lea    0xdff(%rip),%r13
lea    0xe22(%rip),%r15
jmp    123d <io_read+0x8d>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <luaL_buffer@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   10a0 <lua_pushlstring@plt>
mov    0x4(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0x4(%rsp)
xor    %esi,%esi
xor    %edx,%edx
call   1070 <luaL_opt_lstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12b7 <io_read+0x107>
xor    %eax,%eax
call   10c0 <luaL_resetbuffer@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <luaL_findstring@plt>
cmp    $0x4,%eax
ja     126f <io_read+0xbf>
mov    %eax,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r12,%rdi
call   1080 <read_file@plt>
mov    $0x1,%ebp
jmp    129c <io_read+0xec>
mov    %r12,%rdi
mov    %rbx,%rsi
jmp    1295 <io_read+0xe5>
mov    %r12,%rdi
call   10d0 <read_number@plt>
test   %eax,%eax
jne    1221 <io_read+0x71>
jmp    12b7 <io_read+0x107>
mov    %r12,%rdi
call   10b0 <read_line@plt>
jmp    129a <io_read+0xea>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <read_pattern@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <luaL_getsize@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jne    1210 <io_read+0x60>
test   %rbx,%rbx
jne    1210 <io_read+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@io_read.options = internal global [6 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str = [3 x i8] c"*n\00"
@.str.1 = [3 x i8] c"*l\00"
@.str.2 = [3 x i8] c"*a\00"
@.str.3 = [3 x i8] c".*\00"
@.str.4 = [3 x i8] c"*w\00"
@.str.5 = [7 x i8] c"_INPUT\00"
@.str.6 = [9 x i8] c"{%s*}%S+\00"
define void @io_read() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 2, i32* %1
%6 = call i32* @getfileparam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %1)
store i32* %6, i32** %2
%7 = load i32, i32* %1
%8 = add nsw i32 %7, 1
store i32 %8, i32* %1
%9 = call i8* @luaL_opt_lstr(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
store i8* %9, i8** %3
br label %10
10: ; preds = %45, %0
%11 = call i32 (...) @luaL_resetbuffer()
%12 = load i8*, i8** %3
%13 = call i32 @luaL_findstring(i8* %12, i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @io_read.options, i64 0, i64 0))
switch i32 %13, label %29 [
i32 0, label %14
i32 1, label %20
i32 2, label %23
i32 3, label %23
i32 4, label %26
]
14: ; preds = %10
%15 = load i32*, i32** %2
%16 = call i32 @read_number(i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
br label %50
19: ; preds = %14
br label %45
20: ; preds = %10
%21 = load i32*, i32** %2
%22 = call i32 @read_line(i32* %21)
store i32 %22, i32* %5
br label %33
23: ; preds = %10, %10
%24 = load i32*, i32** %2
%25 = call i32 @read_file(i32* %24)
store i32 1, i32* %5
br label %33
26: ; preds = %10
%27 = load i32*, i32** %2
%28 = call i32 @read_pattern(i32* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i32 %28, i32* %5
br label %33
29: ; preds = %10
%30 = load i32*, i32** %2
%31 = load i8*, i8** %3
%32 = call i32 @read_pattern(i32* %30, i8* %31)
store i32 %32, i32* %5
br label %33
33: ; preds = %29, %26, %23, %20
%34 = call i64 (...) @luaL_getsize()
store i64 %34, i64* %4
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i64, i64* %4
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
br label %50
41: ; preds = %37, %33
%42 = call i32 (...) @luaL_buffer()
%43 = load i64, i64* %4
%44 = call i32 @lua_pushlstring(i32 %42, i64 %43)
br label %45
45: ; preds = %41, %19
%46 = load i32, i32* %1
%47 = add nsw i32 %46, 1
store i32 %47, i32* %1
%48 = call i8* @luaL_opt_lstr(i32 %46, i8* null, i32* null)
store i8* %48, i8** %3
%49 = icmp ne i8* %48, null
br i1 %49, label %10, label %50
50: ; preds = %18, %40, %45
ret void
}

LLVM IR (-O2):
@io_read.options = internal global [6 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str = [3 x i8] c"*n\00"
@.str.1 = [3 x i8] c"*l\00"
@.str.2 = [3 x i8] c"*a\00"
@.str.3 = [3 x i8] c".*\00"
@.str.4 = [3 x i8] c"*w\00"
@.str.5 = [7 x i8] c"_INPUT\00"
@.str.6 = [9 x i8] c"{%s*}%S+\00"
define void @io_read() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 2, i32* %1
%3 = call i32* @getfileparam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = call i8* @luaL_opt_lstr(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %7
7: ; preds = %31, %0
%8 = phi i8* [ %6, %0 ], [ %34, %31 ]
%9 = call i32 (...) @luaL_resetbuffer()
%10 = call i32 @luaL_findstring(i8* %8, i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @io_read.options, i64 0, i64 0))
switch i32 %10, label %20 [
i32 0, label %11
i32 1, label %14
i32 2, label %16
i32 3, label %16
i32 4, label %18
]
11: ; preds = %7
%12 = call i32 @read_number(i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %36, label %31
14: ; preds = %7
%15 = call i32 @read_line(i32* %3)
br label %22
16: ; preds = %7, %7
%17 = call i32 @read_file(i32* %3)
br label %22
18: ; preds = %7
%19 = call i32 @read_pattern(i32* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %22
20: ; preds = %7
%21 = call i32 @read_pattern(i32* %3, i8* %8)
br label %22
22: ; preds = %20, %18, %16, %14
%23 = phi i32 [ %21, %20 ], [ %19, %18 ], [ 1, %16 ], [ %15, %14 ]
%24 = call i64 (...) @luaL_getsize()
%25 = icmp eq i32 %23, 0
%26 = icmp eq i64 %24, 0
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %36, label %28
28: ; preds = %22
%29 = call i32 (...) @luaL_buffer()
%30 = call i32 @lua_pushlstring(i32 %29, i64 %24)
br label %31
31: ; preds = %28, %11
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
%34 = call i8* @luaL_opt_lstr(i32 %32, i8* null, i32* null)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %7
36: ; preds = %11, %22, %31
ret void
}