#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 */
#define LC_ALL 133
#define LC_COLLATE 132
#define LC_CTYPE 131
#define LC_MONETARY 130
#define LC_NUMERIC 129
#define LC_TIME 128
int /*<<< orphan*/ luaL_argerror(int, char *);
int /*<<< orphan*/ luaL_check_lstr(int, int /*<<< orphan*/ *);
int luaL_findstring(int /*<<< orphan*/, char **);
int /*<<< orphan*/ luaL_opt_lstr(int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ lua_pushstring(int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int, int /*<<< orphan*/);
void setloc(void) {
  static int cat[] = {LC_ALL,      LC_COLLATE, LC_CTYPE,
                      LC_MONETARY, LC_NUMERIC, LC_TIME};
  static char *catnames[] = {"all",     "collate", "ctype", "monetary",
                             "numeric", "time",    NULL};
  int op = luaL_findstring((luaL_opt_lstr((2), ("all"), NULL)), catnames);
  if (!(op != -1))
    luaL_argerror(2, "invalid option");
  lua_pushstring(setlocale(cat[op], (luaL_check_lstr((1), NULL))));
}


x86 assembly (clang, -O0):
<setloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2,%edi
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <luaL_opt_lstr@plt>
mov    %eax,%edi
lea    0x2efa(%rip),%rsi
call   1040 <luaL_findstring@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a9 <setloc+0x49>
mov    $0x2,%edi
lea    0xe84(%rip),%rsi
call   1030 <luaL_argerror@plt>
movslq -0x4(%rbp),%rcx
lea    0x2eac(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <luaL_check_lstr@plt>
mov    -0x8(%rbp),%edi
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    %eax,%edi
call   1080 <lua_pushstring@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setloc>:
push   %rbx
lea    0xeb0(%rip),%rsi
mov    $0x2,%edi
xor    %edx,%edx
call   1050 <luaL_opt_lstr@plt>
lea    0x2ee5(%rip),%rsi
mov    %eax,%edi
call   1040 <luaL_findstring@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    119a <setloc+0x3a>
lea    0xeb0(%rip),%rsi
mov    $0x2,%edi
call   1030 <luaL_argerror@plt>
movslq %ebx,%rax
lea    0xe5c(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    $0x1,%edi
xor    %esi,%esi
call   1070 <luaL_check_lstr@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    %eax,%edi
pop    %rbx
jmp    1080 <lua_pushstring@plt>

LLVM IR (-O0):
@setloc.cat = internal global [6 x i32] [i32 133, i32 132, i32 131, i32 130, i32 129, i32 128]
@setloc.catnames = internal global [7 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"all\00"
@.str.1 = [8 x i8] c"collate\00"
@.str.2 = [6 x i8] c"ctype\00"
@.str.3 = [9 x i8] c"monetary\00"
@.str.4 = [8 x i8] c"numeric\00"
@.str.5 = [5 x i8] c"time\00"
@.str.6 = [15 x i8] c"invalid option\00"
define void @setloc() {
%1 = alloca i32
%2 = call i32 @luaL_opt_lstr(i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* null)
%3 = call i32 @luaL_findstring(i32 %2, i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @setloc.catnames, i64 0, i64 0))
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp ne i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @luaL_argerror(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32, i32* %1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [6 x i32], [6 x i32]* @setloc.cat, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @luaL_check_lstr(i32 1, i32* null)
%14 = call i32 @setlocale(i32 %12, i32 %13)
%15 = call i32 @lua_pushstring(i32 %14)
ret void
}

LLVM IR (-O2):
@setloc.cat = internal unnamed_addr constant [6 x i32] [i32 133, i32 132, i32 131, i32 130, i32 129, i32 128]
@setloc.catnames = internal global [7 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"all\00"
@.str.1 = [8 x i8] c"collate\00"
@.str.2 = [6 x i8] c"ctype\00"
@.str.3 = [9 x i8] c"monetary\00"
@.str.4 = [8 x i8] c"numeric\00"
@.str.5 = [5 x i8] c"time\00"
@.str.6 = [15 x i8] c"invalid option\00"
define void @setloc() {
%1 = tail call i32 @luaL_opt_lstr(i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* null)
%2 = tail call i32 @luaL_findstring(i32 %1, i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @setloc.catnames, i64 0, i64 0))
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @luaL_argerror(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [6 x i32], [6 x i32]* @setloc.cat, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @luaL_check_lstr(i32 1, i32* null)
%11 = tail call i32 @setlocale(i32 %9, i32 %10)
%12 = tail call i32 @lua_pushstring(i32 %11)
ret void
}