#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_arg_check(int, int, char *);
char *luaL_check_string(int);
scalar_t__ luaL_opt_number(int, int);
int /*<<< orphan*/ lua_pushnumber(unsigned char);
long strlen(char *);
void str_ascii(void) {
  char *s = luaL_check_string(1);
  long pos = (long)luaL_opt_number(2, 1) - 1;
  luaL_arg_check(0 <= pos && pos < strlen(s), 2, "out of range");
  lua_pushnumber((unsigned char)s[pos]);
}


x86 assembly (clang, -O0):
<str_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
call   1050 <luaL_check_string@plt>
mov    %rax,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <luaL_opt_number@plt>
sub    $0x1,%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x10(%rbp),%rcx
mov    %al,-0x11(%rbp)
jg     11af <str_ascii+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x2,%esi
lea    0xe3d(%rip),%rdx
call   1070 <luaL_arg_check@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <lua_pushnumber@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_ascii>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
call   1050 <luaL_check_string@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <luaL_opt_number@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    118b <str_ascii+0x3b>
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %rax,%rbx
setle  %dil
jmp    118d <str_ascii+0x3d>
xor    %edi,%edi
lea    0xe6c(%rip),%rdx
mov    $0x2,%esi
call   1070 <luaL_arg_check@plt>
movzbl -0x1(%rbx,%r14,1),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <lua_pushnumber@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"out of range\00"
define void @str_ascii() {
%1 = alloca i8*
%2 = alloca i64
%3 = call i8* @luaL_check_string(i32 1)
store i8* %3, i8** %1
%4 = call i64 @luaL_opt_number(i32 2, i32 1)
%5 = sub nsw i64 %4, 1
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp sle i64 0, %6
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i64, i64* %2
%10 = load i8*, i8** %1
%11 = call i64 @strlen(i8* %10)
%12 = icmp slt i64 %9, %11
br label %13
13: ; preds = %8, %0
%14 = phi i1 [ false, %0 ], [ %12, %8 ]
%15 = zext i1 %14 to i32
%16 = call i32 @luaL_arg_check(i32 %15, i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %1
%18 = load i64, i64* %2
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @lua_pushnumber(i8 zeroext %20)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"out of range\00"
define void @str_ascii() {
%1 = tail call i8* @luaL_check_string(i32 1)
%2 = tail call i64 @luaL_opt_number(i32 2, i32 1)
%3 = icmp sgt i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = icmp sle i64 %2, %5
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %0
%9 = phi i32 [ 0, %0 ], [ %7, %4 ]
%10 = add nsw i64 %2, -1
%11 = tail call i32 @luaL_arg_check(i32 %9, i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = tail call i32 @lua_pushnumber(i8 zeroext %13)
ret void
}