#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
scalar_t__ isupper(int /*<<< orphan*/);
char tolower(int /*<<< orphan*/);
char *svz_tolower(char *str) {
  char *p = str;
  while (*p) {
    *p = (char)(isupper((uint8_t)*p) ? tolower((uint8_t)*p) : *p);
    p++;
  }
  return str;
}


x86 assembly (clang, -O0):
<svz_tolower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1194 <svz_tolower+0x74>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     116e <svz_tolower+0x4e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <svz_tolower+0x58>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <svz_tolower+0x14>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svz_tolower>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     116b <svz_tolower+0x4b>
mov    %r14,%rbx
jmp    114e <svz_tolower+0x2e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     116b <svz_tolower+0x4b>
movsbl %al,%edi
call   1040 <isupper@plt>
mov    %rax,%rcx
movzbl (%rbx),%eax
test   %rcx,%rcx
je     1140 <svz_tolower+0x20>
movsbl %al,%edi
call   1030 <tolower@plt>
jmp    1140 <svz_tolower+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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