#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*/ isalpha(char);
scalar_t__ islower(char);
char *strlower(char *str) {
  char *p;
  for (p = str; *p != '\0'; ++p)
    *p = ((!isalpha(*p) || islower(*p)) ? (*p) : ((*p) - 'A' + 'a'));
  return (str);
}


x86 assembly (clang, -O0):
<strlower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11aa <strlower+0x8a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%eax
je     116f <strlower+0x4f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     117e <strlower+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    118e <strlower+0x6e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x41,%eax
add    $0x61,%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 <strlower+0x14>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strlower>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     1171 <strlower+0x51>
mov    %r14,%rbx
jmp    1151 <strlower+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%eax
mov    %al,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1171 <strlower+0x51>
movsbl %al,%edi
call   1040 <isalpha@plt>
test   %eax,%eax
je     1140 <strlower+0x20>
movsbl (%rbx),%edi
call   1030 <islower@plt>
test   %rax,%rax
jne    1140 <strlower+0x20>
movzbl (%rbx),%eax
add    $0x20,%al
jmp    1143 <strlower+0x23>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @strlower(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 = %34, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %37
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = call i32 @isalpha(i8 signext %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = call i64 @islower(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15, %10
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
br label %30
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 65
%29 = add nsw i32 %28, 97
br label %30
30: ; preds = %24, %20
%31 = phi i32 [ %23, %20 ], [ %29, %24 ]
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %3
store i8 %32, i8* %33
br label %34
34: ; preds = %30
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
br label %5
37: ; preds = %5
%38 = load i8*, i8** %2
ret i8* %38
}

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