#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*/ luaI_addchar(int /*<<< orphan*/);
int /*<<< orphan*/ luaI_emptybuff();
char *luaL_check_string(int);
int /*<<< orphan*/ lua_pushstring(int /*<<< orphan*/);
int /*<<< orphan*/ toupper(unsigned char);
void str_upper(void) {
  char *s;
  luaI_emptybuff();
  for (s = luaL_check_string(1); *s; s++)
    luaI_addchar(toupper((unsigned char)*s));
  lua_pushstring(luaI_addchar(0));
}


x86 assembly (clang, -O0):
<str_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <luaI_emptybuff@plt>
mov    $0x1,%edi
call   1050 <luaL_check_string@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     119e <str_upper+0x4e>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%edi
call   1060 <luaI_addchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116d <str_upper+0x1d>
xor    %edi,%edi
call   1060 <luaI_addchar@plt>
mov    %eax,%edi
call   1070 <lua_pushstring@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_upper>:
push   %rbx
xor    %eax,%eax
call   1040 <luaI_emptybuff@plt>
mov    $0x1,%edi
call   1050 <luaL_check_string@plt>
mov    %rax,%rbx
mov    (%rax),%al
test   %al,%al
je     118a <str_upper+0x3a>
add    $0x1,%rbx
nop
movzbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%edi
call   1060 <luaI_addchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <str_upper+0x20>
xor    %edi,%edi
call   1060 <luaI_addchar@plt>
mov    %eax,%edi
pop    %rbx
jmp    1070 <lua_pushstring@plt>

LLVM IR (-O0):
define void @str_upper() {
%1 = alloca i8*
%2 = call i32 (...) @luaI_emptybuff()
%3 = call i8* @luaL_check_string(i32 1)
store i8* %3, i8** %1
br label %4
4: ; preds = %13, %0
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = load i8*, i8** %1
%10 = load i8, i8* %9
%11 = call i32 @toupper(i8 zeroext %10)
%12 = call i32 @luaI_addchar(i32 %11)
br label %13
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %1
br label %4
16: ; preds = %4
%17 = call i32 @luaI_addchar(i32 0)
%18 = call i32 @lua_pushstring(i32 %17)
ret void
}

LLVM IR (-O2):
define void @str_upper() {
%1 = tail call i32 (...) @luaI_emptybuff()
%2 = tail call i8* @luaL_check_string(i32 1)
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %11, %5 ], [ %3, %0 ]
%7 = phi i8* [ %10, %5 ], [ %2, %0 ]
%8 = tail call i32 @toupper(i8 zeroext %6)
%9 = tail call i32 @luaI_addchar(i32 %8)
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %5
13: ; preds = %5, %0
%14 = tail call i32 @luaI_addchar(i32 0)
%15 = tail call i32 @lua_pushstring(i32 %14)
ret void
}