#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__ islower(char);
char tolower(char);
char toupper(char);
void convert(char *s) {
  while (*s != '\0') {
    if (islower(*s))
      *s = toupper(*s);
    else
      *s = tolower(*s);
    s++;
  }
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a0 <convert+0x70>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     117b <convert+0x4b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    118f <convert+0x5f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <convert+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     116d <convert+0x3d>
mov    %rdi,%rbx
jmp    1153 <convert+0x23>
nopl   0x0(%rax)
call   1050 <tolower@plt>
mov    %al,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     116d <convert+0x3d>
movsbl %al,%edi
call   1030 <islower@plt>
movzbl (%rbx),%ecx
movsbl %cl,%edi
test   %rax,%rax
je     1140 <convert+0x10>
call   1040 <toupper@plt>
jmp    1145 <convert+0x15>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @convert(i8* nocapture %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 = tail call i64 @islower(i8 signext %5)
%8 = icmp eq i64 %7, 0
%9 = load i8, i8* %6
br i1 %8, label %12, label %10
10: ; preds = %4
%11 = tail call signext i8 @toupper(i8 signext %9)
br label %14
12: ; preds = %4
%13 = tail call signext i8 @tolower(i8 signext %9)
br label %14
14: ; preds = %12, %10
%15 = phi i8 [ %13, %12 ], [ %11, %10 ]
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 void
}