#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__ isupper(int);
char tolower(int);
void lowercase(char *s) {
  int c;
  if (s) {
    for (; (c = (int)(*(unsigned const char *)(s))); ++s) {
      if (isupper(c))
        *s = tolower(c);
    }
  }
}


x86 assembly (clang, -O0):
<lowercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118c <lowercase+0x6c>
jmp    113c <lowercase+0x1c>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1187 <lowercase+0x67>
mov    -0xc(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     1171 <lowercase+0x51>
mov    -0xc(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    1176 <lowercase+0x56>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <lowercase+0x1c>
jmp    118c <lowercase+0x6c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lowercase>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1166 <lowercase+0x46>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1166 <lowercase+0x46>
add    $0x1,%rbx
jmp    114b <lowercase+0x2b>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1166 <lowercase+0x46>
movzbl %al,%ebp
mov    %ebp,%edi
call   1040 <isupper@plt>
test   %rax,%rax
je     1140 <lowercase+0x20>
mov    %ebp,%edi
call   1030 <tolower@plt>
mov    %al,-0x1(%rbx)
jmp    1140 <lowercase+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @lowercase(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %25
6: ; preds = %1
br label %7
7: ; preds = %21, %6
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load i32, i32* %3
%14 = call i64 @isupper(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call signext i8 @tolower(i32 %17)
%19 = load i8*, i8** %2
store i8 %18, i8* %19
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
br label %7
24: ; preds = %7
br label %25
25: ; preds = %24, %1
ret void
}

LLVM IR (-O2):
define void @lowercase(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %14
%7 = phi i8 [ %16, %14 ], [ %4, %3 ]
%8 = phi i8* [ %15, %14 ], [ %0, %3 ]
%9 = zext i8 %7 to i32
%10 = tail call i64 @isupper(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call signext i8 @tolower(i32 %9)
store i8 %13, i8* %8
br label %14
14: ; preds = %6, %12
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %14, %3, %1
ret void
}