#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_argerror(int, char *);
char *luaL_check_lstr(int, long *);
int /*<<< orphan*/ luaL_opt_number(int, int);
int /*<<< orphan*/ lua_pushnumber(unsigned char);
long posrelat(int /*<<< orphan*/, long);
void str_byte(void) {
  long l;
  char *s = luaL_check_lstr(1, &l);
  long pos = posrelat(luaL_opt_number(2, 1), l);
  if (!(0 < pos && pos <= l))
    luaL_argerror(2, "out of range");
  lua_pushnumber((unsigned char)s[pos - 1]);
}


x86 assembly (clang, -O0):
<str_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
call   1070 <luaL_check_lstr@plt>
mov    %rax,-0x10(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <luaL_opt_number@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1060 <posrelat@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jge    11a2 <str_byte+0x52>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jle    11b3 <str_byte+0x63>
mov    $0x2,%edi
lea    0xe52(%rip),%rsi
call   1040 <luaL_argerror@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <lua_pushnumber@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_byte>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
mov    $0x1,%edi
call   1070 <luaL_check_lstr@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <luaL_opt_number@plt>
mov    (%rsp),%rsi
mov    %eax,%edi
call   1060 <posrelat@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    118c <str_byte+0x3c>
cmp    (%rsp),%rbx
jle    119d <str_byte+0x4d>
lea    0xe6d(%rip),%rsi
mov    $0x2,%edi
call   1040 <luaL_argerror@plt>
movzbl -0x1(%rbx,%r14,1),%edi
call   1050 <lua_pushnumber@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"out of range\00"
define void @str_byte() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i8* @luaL_check_lstr(i32 1, i64* %1)
%4 = call i32 @luaL_opt_number(i32 2, i32 1)
%5 = load i64, i64* %1
%6 = call i64 @posrelat(i32 %4, i64 %5)
%7 = icmp slt i64 %6, 1
%8 = load i64, i64* %1
%9 = icmp sgt i64 %6, %8
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @luaL_argerror(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %11
%14 = add nsw i64 %6, -1
%15 = getelementptr inbounds i8, i8* %3, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @lua_pushnumber(i8 zeroext %16)
ret void
}