#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__ isascii(int);
scalar_t__ isupper(int);
char tolower(int);
void downcase(char *p) {
  int ch;
  for (; (ch = *p) != '\0'; ++p)
    if (isascii(ch) && isupper(ch))
      *p = tolower(ch);
}


x86 assembly (clang, -O0):
<downcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1199 <downcase+0x69>
mov    -0xc(%rbp),%edi
call   1050 <isascii@plt>
cmp    $0x0,%rax
je     1183 <downcase+0x53>
mov    -0xc(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     1183 <downcase+0x53>
mov    -0xc(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    1188 <downcase+0x58>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <downcase+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<downcase>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1182 <downcase+0x52>
mov    %rdi,%rbx
add    $0x1,%rbx
jmp    115b <downcase+0x2b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1182 <downcase+0x52>
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isascii@plt>
test   %rax,%rax
je     1150 <downcase+0x20>
mov    %ebp,%edi
call   1040 <isupper@plt>
test   %rax,%rax
je     1150 <downcase+0x20>
mov    %ebp,%edi
call   1030 <tolower@plt>
mov    %al,-0x1(%rbx)
jmp    1150 <downcase+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @downcase(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %15
%5 = phi i8 [ %17, %15 ], [ %2, %1 ]
%6 = phi i8* [ %16, %15 ], [ %0, %1 ]
%7 = sext i8 %5 to i32
%8 = tail call i64 @isascii(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = tail call i64 @isupper(i32 %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call signext i8 @tolower(i32 %7)
store i8 %14, i8* %6
br label %15
15: ; preds = %4, %10, %13
%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 = %15, %1
ret void
}