#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*/ luaL_verror(char *, int, char *, ...);
int /*<<< orphan*/ lua_getobjname(int /*<<< orphan*/, char **);
int /*<<< orphan*/ lua_stackedfunction(int /*<<< orphan*/);
void luaL_arg_check(int cond, int numarg, char *extramsg) {
  if (!cond) {
    char *funcname;
    lua_getobjname(lua_stackedfunction(0), &funcname);
    if (funcname == NULL)
      funcname = "???";
    if (extramsg == NULL)
      luaL_verror("bad argument #%d to function `%s'", numarg, funcname);
    else
      luaL_verror("bad argument #%d to function `%s' (%s)", numarg, funcname,
                  extramsg);
  }
}


x86 assembly (clang, -O0):
<luaL_arg_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b7 <luaL_arg_check+0x87>
xor    %edi,%edi
call   1030 <lua_stackedfunction@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <lua_getobjname@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1174 <luaL_arg_check+0x44>
lea    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <luaL_arg_check+0x69>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <luaL_verror@plt>
jmp    11b2 <luaL_arg_check+0x82>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <luaL_verror@plt>
jmp    11b7 <luaL_arg_check+0x87>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaL_arg_check>:
test   %edi,%edi
je     1135 <luaL_arg_check+0x5>
ret
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
xor    %edi,%edi
call   1030 <lua_stackedfunction@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <lua_getobjname@plt>
mov    (%rsp),%rdx
test   %rdx,%rdx
je     1171 <luaL_arg_check+0x41>
test   %rbx,%rbx
je     1181 <luaL_arg_check+0x51>
lea    0xec3(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <luaL_verror@plt>
jmp    1191 <luaL_arg_check+0x61>
lea    0xe88(%rip),%rdx
mov    %rdx,(%rsp)
test   %rbx,%rbx
jne    115c <luaL_arg_check+0x2c>
lea    0xe7c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <luaL_verror@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"???\00"
@.str.1 = [34 x i8] c"bad argument #%d to function `%s'\00"
@.str.2 = [39 x i8] c"bad argument #%d to function `%s' (%s)\00"
define void @luaL_arg_check(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %29, label %10
10: ; preds = %3
%11 = call i32 @lua_stackedfunction(i32 0)
%12 = call i32 @lua_getobjname(i32 %11, i8** %7)
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
br label %16
16: ; preds = %15, %10
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %5
%21 = load i8*, i8** %7
%22 = call i32 (i8*, i32, i8*, ...) @luaL_verror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
br label %28
23: ; preds = %16
%24 = load i32, i32* %5
%25 = load i8*, i8** %7
%26 = load i8*, i8** %6
%27 = call i32 (i8*, i32, i8*, ...) @luaL_verror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %25, i8* %26)
br label %28
28: ; preds = %23, %19
br label %29
29: ; preds = %28, %3
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"???\00"
@.str.1 = [34 x i8] c"bad argument #%d to function `%s'\00"
@.str.2 = [39 x i8] c"bad argument #%d to function `%s' (%s)\00"
define void @luaL_arg_check(i32 %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = bitcast i8** %4 to i8*
%8 = tail call i32 @lua_stackedfunction(i32 0)
%9 = call i32 @lua_getobjname(i32 %8, i8** %4)
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %6
%14 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %12 ], [ %10, %6 ]
%15 = icmp eq i8* %2, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, i32, i8*, ...) @luaL_verror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %14)
br label %20
18: ; preds = %13
%19 = call i32 (i8*, i32, i8*, ...) @luaL_verror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* %14, i8* %2)
br label %20
20: ; preds = %18, %16
br label %21
21: ; preds = %20, %3
ret void
}