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


x86 assembly (clang, -O0):
<str_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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   1050 <lua_opt_number@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x10(%rbp),%rcx
mov    %al,-0x11(%rbp)
jg     11be <str_ascii+0x6e>
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
lea    0xe33(%rip),%rsi
call   1070 <lua_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   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%r14
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <lua_check_string@plt>
mov    %rax,%r15
mov    $0x2,%edi
mov    $0x1,%esi
mov    %r14,%rdx
call   1050 <lua_opt_number@plt>
cltq
lea    -0x1(%rax),%rbx
test   %eax,%eax
jle    119b <str_ascii+0x4b>
mov    %r15,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %rbx,%rax
setg   %dil
jmp    119d <str_ascii+0x4d>
xor    %edi,%edi
lea    0xe5c(%rip),%rsi
call   1070 <lua_arg_check@plt>
movzbl (%r15,%rbx,1),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <lua_pushnumber@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"ascii\00"
define void @str_ascii() {
%1 = alloca i8*
%2 = alloca i64
%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
%6 = sext i32 %5 to i64
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp sle i64 0, %7
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i64, i64* %2
%11 = load i8*, i8** %1
%12 = call i64 @strlen(i8* %11)
%13 = icmp slt i64 %10, %12
br label %14
14: ; preds = %9, %0
%15 = phi i1 [ false, %0 ], [ %13, %9 ]
%16 = zext i1 %15 to i32
%17 = call i32 @lua_arg_check(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %1
%19 = load i64, i64* %2
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @lua_pushnumber(i8 zeroext %21)
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 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = icmp sgt i64 %7, %4
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %6, %0
%11 = phi i32 [ 0, %0 ], [ %9, %6 ]
%12 = tail call i32 @lua_arg_check(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %1, i64 %4
%14 = load i8, i8* %13
%15 = tail call i32 @lua_pushnumber(i8 zeroext %14)
ret void
}