#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*/ lua_arg_error(char *);
char *lua_check_string(int, char *);
int lua_opt_number(int, int, char *);
int /*<<< orphan*/ lua_pushnumber(char);
int strlen(char *);
void str_ascii(void) {
  char *s = lua_check_string(1, "ascii");
  int pos = lua_opt_number(2, 1, "ascii") - 1;
  if (pos < 0 || pos >= strlen(s))
    lua_arg_error("ascii");
  lua_pushnumber(s[pos]);
}


x86 assembly (clang, -O0):
<str_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
lea    0xe9c(%rip),%rsi
call   1030 <lua_check_string@plt>
mov    %rax,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
lea    0xe82(%rip),%rdx
call   1060 <lua_opt_number@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11af <str_ascii+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jl     11bb <str_ascii+0x6b>
lea    0xe4a(%rip),%rdi
call   1040 <lua_arg_error@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <lua_pushnumber@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_ascii>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rbp
mov    $0x1,%edi
mov    %rbp,%rsi
call   1030 <lua_check_string@plt>
mov    %rax,%rbx
mov    $0x2,%edi
mov    $0x1,%esi
mov    %rbp,%rdx
call   1060 <lua_opt_number@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    118e <str_ascii+0x3e>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebp
jle    119a <str_ascii+0x4a>
lea    0xe6b(%rip),%rdi
call   1040 <lua_arg_error@plt>
movslq %ebp,%rax
movsbl -0x1(%rax,%rbx,1),%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <lua_pushnumber@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"ascii\00"
define void @str_ascii() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = call i32 @lua_opt_number(i32 2, i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = sub nsw i32 %4, 1
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %0
%9 = load i32, i32* %2
%10 = load i8*, i8** %1
%11 = call i32 @strlen(i8* %10)
%12 = icmp sge i32 %9, %11
br i1 %12, label %13, label %15
13: ; preds = %8, %0
%14 = call i32 @lua_arg_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = load i8*, i8** %1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @lua_pushnumber(i8 signext %20)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"ascii\00"
define void @str_ascii() {
%1 = tail call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @lua_opt_number(i32 2, i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp slt i32 %2, 1
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %2, %5
br i1 %6, label %7, label %9
7: ; preds = %4, %0
%8 = tail call i32 @lua_arg_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = add nsw i32 %2, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @lua_pushnumber(i8 signext %13)
ret void
}