#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 */
scalar_t__ tolower(char);
char *Nx_strlwr(char *str) {
  static char string[2][32000] = {{0}};
  static int idx = 0;
  char *buf = string[idx++ & 1];
  int i = 0;
  for (i = 0; *str; str++)
    buf[i++] = (char)tolower(*str);
  buf[i] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<Nx_strlwr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x1291e(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x12913(%rip)
and    $0x1,%eax
movslq %eax,%rcx
lea    0x2f06(%rip),%rax
imul   $0x7d00,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1197 <Nx_strlwr+0x87>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1156 <Nx_strlwr+0x46>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Nx_strlwr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x12921(%rip),%r14d
lea    0x1(%r14),%eax
mov    %eax,0x12917(%rip)
and    $0x1,%r14d
mov    (%rdi),%al
test   %al,%al
je     1171 <Nx_strlwr+0x61>
mov    %rdi,%r15
imul   $0x7d00,%r14,%rcx
lea    0x2efc(%rip),%r12
add    %rcx,%r12
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %rcx,%rbx
movsbl %al,%edi
call   1030 <tolower@plt>
lea    0x1(%rbx),%rcx
mov    %al,(%r12,%rbx,1)
movzbl 0x1(%r15,%rbx,1),%eax
test   %al,%al
jne    1150 <Nx_strlwr+0x40>
mov    %ecx,%ecx
jmp    1173 <Nx_strlwr+0x63>
xor    %ecx,%ecx
imul   $0x7d00,%r14,%rdx
lea    0x2ebf(%rip),%rax
add    %rdx,%rax
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@Nx_strlwr.string = internal global [2 x [32000 x i8]] zeroinitializer
@Nx_strlwr.idx = internal global i32 0
define i8* @Nx_strlwr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @Nx_strlwr.idx
%6 = add nsw i32 %5, 1
store i32 %6, i32* @Nx_strlwr.idx
%7 = and i32 %5, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [2 x [32000 x i8]], [2 x [32000 x i8]]* @Nx_strlwr.string, i64 0, i64 %8
%10 = getelementptr inbounds [32000 x i8], [32000 x i8]* %9, i64 0, i64 0
store i8* %10, i8** %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %11
11: ; preds = %25, %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call i64 @tolower(i8 signext %17)
%19 = trunc i64 %18 to i8
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
br label %25
25: ; preds = %15
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
br label %11
28: ; preds = %11
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@Nx_strlwr.string = internal global [2 x [32000 x i8]] zeroinitializer
@Nx_strlwr.idx = internal unnamed_addr global i32 0
define i8* @Nx_strlwr(i8* nocapture %0) {
%2 = load i32, i32* @Nx_strlwr.idx
%3 = add nsw i32 %2, 1
store i32 %3, i32* @Nx_strlwr.idx
%4 = and i32 %2, 1
%5 = zext i32 %4 to i64
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %14, %8 ], [ 0, %1 ]
%10 = phi i8 [ %17, %8 ], [ %6, %1 ]
%11 = phi i8* [ %16, %8 ], [ %0, %1 ]
%12 = tail call i64 @tolower(i8 signext %10)
%13 = trunc i64 %12 to i8
%14 = add nuw i64 %9, 1
%15 = getelementptr inbounds [2 x [32000 x i8]], [2 x [32000 x i8]]* @Nx_strlwr.string, i64 0, i64 %5, i64 %9
store i8 %13, i8* %15
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %8
%20 = and i64 %14, 4294967295
br label %21
21: ; preds = %19, %1
%22 = phi i64 [ 0, %1 ], [ %20, %19 ]
%23 = getelementptr inbounds [2 x [32000 x i8]], [2 x [32000 x i8]]* @Nx_strlwr.string, i64 0, i64 %5, i64 0
%24 = getelementptr inbounds [2 x [32000 x i8]], [2 x [32000 x i8]]* @Nx_strlwr.string, i64 0, i64 %5, i64 %22
store i8 0, i8* %24
ret i8* %23
}