#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 */
char *locase(const char *str) {
  char c;
  static char buf[100];
  char *p = buf;
  while ((c = *str++)) {
    *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
  }
  *p = 0;
  return (buf);
}


x86 assembly (clang, -O0):
<locase>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
cmp    $0x0,%al
je     117d <locase+0x7d>
movsbl -0x9(%rbp),%eax
cmp    $0x41,%eax
jl     115b <locase+0x5b>
movsbl -0x9(%rbp),%eax
cmp    $0x5a,%eax
jg     115b <locase+0x5b>
movsbl -0x9(%rbp),%eax
sub    $0x41,%eax
add    $0x61,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <locase+0x62>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1113 <locase+0x13>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2ea5(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<locase>:
mov    (%rdi),%cl
test   %cl,%cl
je     1146 <locase+0x46>
add    $0x1,%rdi
lea    0x2f1f(%rip),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x41(%rcx),%edx
lea    0x20(%rcx),%esi
cmp    $0x1a,%dl
movzbl %cl,%ecx
movzbl %sil,%edx
cmovae %ecx,%edx
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1120 <locase+0x20>
jmp    114d <locase+0x4d>
lea    0x2ee3(%rip),%rax
movb   $0x0,(%rax)
lea    0x2ed9(%rip),%rax
ret

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

LLVM IR (-O2):
@locase.buf = internal global [100 x i8] zeroinitializer
define i8* @locase(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %14, %4 ], [ %2, %1 ]
%6 = phi i8* [ %13, %4 ], [ getelementptr inbounds ([100 x i8], [100 x i8]* @locase.buf, i64 0, i64 0), %1 ]
%7 = phi i8* [ %8, %4 ], [ %0, %1 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = add i8 %5, -65
%10 = icmp ult i8 %9, 26
%11 = add i8 %5, 32
%12 = select i1 %10, i8 %11, i8 %5
%13 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %12, i8* %6
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %1
%17 = phi i8* [ getelementptr inbounds ([100 x i8], [100 x i8]* @locase.buf, i64 0, i64 0), %1 ], [ %13, %4 ]
store i8 0, i8* %17
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @locase.buf, i64 0, i64 0)
}