#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*/ closeandpush();
int /*<<< orphan*/ luaL_addchar(int /*<<< orphan*/);
char *luaL_check_lstr(int, long *);
int /*<<< orphan*/ luaL_resetbuffer();
int /*<<< orphan*/ tolower(unsigned char);
void str_lower(void) {
  long l;
  int i;
  char *s = luaL_check_lstr(1, &l);
  luaL_resetbuffer();
  for (i = 0; i < l; i++)
    luaL_addchar(tolower((unsigned char)(s[i])));
  closeandpush();
}


x86 assembly (clang, -O0):
<str_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
call   1070 <luaL_check_lstr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <luaL_resetbuffer@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11ac <str_lower+0x5c>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%edi
call   1030 <luaL_addchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <str_lower+0x28>
mov    $0x0,%al
call   1050 <closeandpush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_lower>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
mov    $0x1,%edi
call   1070 <luaL_check_lstr@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <luaL_resetbuffer@plt>
cmpq   $0x0,(%rsp)
jle    119b <str_lower+0x4b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%edi
call   1030 <luaL_addchar@plt>
add    $0x1,%rbx
cmp    %rbx,(%rsp)
jg     1180 <str_lower+0x30>
xor    %eax,%eax
call   1050 <closeandpush@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @str_lower() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i8*
%4 = call i8* @luaL_check_lstr(i32 1, i64* %1)
store i8* %4, i8** %3
%5 = call i32 (...) @luaL_resetbuffer()
store i32 0, i32* %2
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = load i64, i64* %1
%10 = icmp slt i64 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @tolower(i8 zeroext %16)
%18 = call i32 @luaL_addchar(i32 %17)
br label %19
19: ; preds = %11
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %6
22: ; preds = %6
%23 = call i32 (...) @closeandpush()
ret void
}

LLVM IR (-O2):
define void @str_lower() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i8* @luaL_check_lstr(i32 1, i64* %1)
%4 = call i32 (...) @luaL_resetbuffer()
%5 = load i64, i64* %1
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0, %7
%8 = phi i64 [ %13, %7 ], [ 0, %0 ]
%9 = getelementptr inbounds i8, i8* %3, i64 %8
%10 = load i8, i8* %9
%11 = call i32 @tolower(i8 zeroext %10)
%12 = call i32 @luaL_addchar(i32 %11)
%13 = add nuw nsw i64 %8, 1
%14 = load i64, i64* %1
%15 = icmp sgt i64 %14, %13
br i1 %15, label %7, label %16
16: ; preds = %7, %0
%17 = call i32 (...) @closeandpush()
ret void
}