#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*/);
char *lua_check_string(int, char *);
int /*<<< orphan*/ lua_pushstring(int /*<<< orphan*/);
int /*<<< orphan*/ tolower(int /*<<< orphan*/);
void str_lower(void) {
  char *s = lua_check_string(1, "strlower");
  luaI_addchar(0);
  while (*s)
    luaI_addchar(tolower(*s++));
  lua_pushstring(luaI_addchar(0));
}


x86 assembly (clang, -O0):
<str_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
lea    0xeac(%rip),%rsi
call   1030 <lua_check_string@plt>
mov    %rax,-0x8(%rbp)
xor    %edi,%edi
call   1040 <luaI_addchar@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1194 <str_lower+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %eax,%edi
call   1040 <luaI_addchar@plt>
jmp    1164 <str_lower+0x24>
xor    %edi,%edi
call   1040 <luaI_addchar@plt>
mov    %eax,%edi
call   1060 <lua_pushstring@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_lower>:
push   %rbx
lea    0xeb8(%rip),%rsi
mov    $0x1,%edi
call   1030 <lua_check_string@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <luaI_addchar@plt>
mov    (%rbx),%al
test   %al,%al
je     118a <str_lower+0x4a>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %eax,%edi
call   1040 <luaI_addchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <str_lower+0x30>
xor    %edi,%edi
call   1040 <luaI_addchar@plt>
mov    %eax,%edi
pop    %rbx
jmp    1060 <lua_pushstring@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"strlower\00"
define void @str_lower() {
%1 = alloca i8*
%2 = call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = call i32 @luaI_addchar(i32 0)
br label %4
4: ; preds = %8, %0
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %1
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
%13 = call i32 @tolower(i32 %12)
%14 = call i32 @luaI_addchar(i32 %13)
br label %4
15: ; preds = %4
%16 = call i32 @luaI_addchar(i32 0)
%17 = call i32 @lua_pushstring(i32 %16)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"strlower\00"
define void @str_lower() {
%1 = tail call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @luaI_addchar(i32 0)
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %12, %5 ], [ %3, %0 ]
%7 = phi i8* [ %8, %5 ], [ %1, %0 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = sext i8 %6 to i32
%10 = tail call i32 @tolower(i32 %9)
%11 = tail call i32 @luaI_addchar(i32 %10)
%12 = load i8, i8* %8
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %5
14: ; preds = %5, %0
%15 = tail call i32 @luaI_addchar(i32 0)
%16 = tail call i32 @lua_pushstring(i32 %15)
ret void
}