#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*/ closeandpush();
int /*<<< orphan*/ luaL_addchar(unsigned char);
int /*<<< orphan*/ luaL_argerror(int, char *);
double luaL_check_number(int);
int /*<<< orphan*/ luaL_resetbuffer();
scalar_t__ lua_lua2C(int);
void str_char(void) {
  int i = 0;
  luaL_resetbuffer();
  while (lua_lua2C(++i) != 0) {
    double c = luaL_check_number(i);
    if (!((unsigned char)c == c))
      luaL_argerror(i, "invalid value");
    luaL_addchar((unsigned char)c);
  }
  closeandpush();
}


x86 assembly (clang, -O0):
<str_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <luaL_resetbuffer@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x4(%rbp)
call   1080 <lua_lua2C@plt>
cmp    $0x0,%rax
je     11de <str_char+0x7e>
mov    -0x4(%rbp),%edi
call   1040 <luaL_check_number@plt>
movsd  %xmm0,-0x10(%rbp)
cvttsd2si -0x10(%rbp),%eax
movzbl %al,%eax
cvtsi2sd %eax,%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11bd <str_char+0x5d>
jp     11bd <str_char+0x5d>
jmp    11cc <str_char+0x6c>
mov    -0x4(%rbp),%edi
lea    0xe39(%rip),%rsi
call   1030 <luaL_argerror@plt>
cvttsd2si -0x10(%rbp),%eax
movzbl %al,%edi
call   1050 <luaL_addchar@plt>
jmp    1176 <str_char+0x16>
mov    $0x0,%al
call   1060 <closeandpush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <luaL_resetbuffer@plt>
mov    $0x1,%edi
call   1080 <lua_lua2C@plt>
test   %rax,%rax
je     11d5 <str_char+0x75>
mov    $0x2,%ebx
lea    0xe77(%rip),%r14
jmp    11a6 <str_char+0x46>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <luaL_addchar@plt>
mov    %ebx,%edi
call   1080 <lua_lua2C@plt>
add    $0x1,%ebx
test   %rax,%rax
je     11d5 <str_char+0x75>
lea    -0x1(%rbx),%r15d
mov    %r15d,%edi
call   1040 <luaL_check_number@plt>
cvttsd2si %xmm0,%eax
movzbl %al,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
ucomisd %xmm1,%xmm0
jne    11c8 <str_char+0x68>
jnp    1190 <str_char+0x30>
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <luaL_argerror@plt>
jmp    1190 <str_char+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <closeandpush@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"invalid value\00"
define void @str_char() {
%1 = alloca i32
%2 = alloca double
store i32 0, i32* %1
%3 = call i32 (...) @luaL_resetbuffer()
br label %4
4: ; preds = %21, %0
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 1
store i32 %6, i32* %1
%7 = call i64 @lua_lua2C(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %4
%10 = load i32, i32* %1
%11 = call double @luaL_check_number(i32 %10)
store double %11, double* %2
%12 = load double, double* %2
%13 = fptoui double %12 to i8
%14 = zext i8 %13 to i32
%15 = sitofp i32 %14 to double
%16 = load double, double* %2
%17 = fcmp oeq double %15, %16
br i1 %17, label %21, label %18
18: ; preds = %9
%19 = load i32, i32* %1
%20 = call i32 @luaL_argerror(i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %9
%22 = load double, double* %2
%23 = fptoui double %22 to i8
%24 = call i32 @luaL_addchar(i8 zeroext %23)
br label %4
25: ; preds = %4
%26 = call i32 (...) @closeandpush()
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"invalid value\00"
define void @str_char() {
%1 = tail call i32 (...) @luaL_resetbuffer()
%2 = tail call i64 @lua_lua2C(i32 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %0, %12
%5 = phi i32 [ %14, %12 ], [ 1, %0 ]
%6 = tail call double @luaL_check_number(i32 %5)
%7 = fptoui double %6 to i8
%8 = uitofp i8 %7 to double
%9 = fcmp oeq double %6, %8
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @luaL_argerror(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
%13 = tail call i32 @luaL_addchar(i8 zeroext %7)
%14 = add nuw nsw i32 %5, 1
%15 = tail call i64 @lua_lua2C(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %4
17: ; preds = %12, %0
%18 = tail call i32 (...) @closeandpush()
ret void
}