#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*/ memset(char *, int /*<<< orphan*/, int);
char tolower(char);
char *strlwc(char *s) {
  static char l[1024 + 1];
  int i;
  if (s == NULL)
    return NULL;
  memset(l, 0, 1024 + 1);
  i = 0;
  while (s[i] && i < 1024) {
    l[i] = tolower(s[i]);
    i++;
  }
  l[1024] = (char)0;
  return l;
}


x86 assembly (clang, -O0):
<strlwc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <strlwc+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11d6 <strlwc+0xb6>
lea    0x2ef5(%rip),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1030 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1185 <strlwc+0x65>
cmpl   $0x400,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1195 <strlwc+0x75>
jmp    11c4 <strlwc+0xa4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
movslq -0x14(%rbp),%rcx
lea    0x2e8d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <strlwc+0x3e>
movb   $0x0,0x3275(%rip)
lea    0x2e6e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strlwc>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     117f <strlwc+0x5f>
mov    %rdi,%r15
lea    0x2f0c(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1030 <memset@plt>
mov    (%r15),%al
test   %al,%al
je     1176 <strlwc+0x56>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,(%rbx,%r14,1)
movzbl 0x1(%r15,%rbx,1),%eax
test   %al,%al
je     1176 <strlwc+0x56>
lea    0x1(%rbx),%rcx
cmp    $0x3ff,%rbx
mov    %rcx,%rbx
jb     1150 <strlwc+0x30>
movb   $0x0,0x32c3(%rip)
jmp    1182 <strlwc+0x62>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@strlwc.l = internal global [1025 x i8] zeroinitializer
define i8* @strlwc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %36
8: ; preds = %1
%9 = call i32 @memset(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 0), i32 0, i32 1025)
store i32 0, i32* %4
br label %10
10: ; preds = %23, %8
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 1024
br label %21
21: ; preds = %18, %10
%22 = phi i1 [ false, %10 ], [ %20, %18 ]
br i1 %22, label %23, label %35
23: ; preds = %21
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call signext i8 @tolower(i8 signext %28)
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 %31
store i8 %29, i8* %32
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %10
35: ; preds = %21
store i8 0, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 1024)
store i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 0), i8** %2
br label %36
36: ; preds = %35, %7
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@strlwc.l = internal global [1025 x i8] zeroinitializer
define i8* @strlwc(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i32 @memset(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 0), i32 0, i32 1025)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %12, %7 ], [ 0, %3 ]
%9 = phi i8 [ %14, %7 ], [ %5, %3 ]
%10 = tail call signext i8 @tolower(i8 signext %9)
%11 = getelementptr inbounds [1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 %8
store i8 %10, i8* %11
%12 = add nuw nsw i64 %8, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = icmp ult i64 %8, 1023
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %7, label %18
18: ; preds = %7, %3
store i8 0, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 1024)
br label %19
19: ; preds = %1, %18
%20 = phi i8* [ getelementptr inbounds ([1025 x i8], [1025 x i8]* @strlwc.l, i64 0, i64 0), %18 ], [ null, %1 ]
ret i8* %20
}