#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);
scalar_t__ isupper(char);
char tolower(char);
char toupper(char);
char *Capitalise(char *str) {
  register char *ptr;
  static char area[1024];
  ptr = area;
  while (*str) {
    *(ptr++) = (isupper(*str) ? tolower(*str) : (*str));
    str++;
  }
  *ptr = '\0';
  area[0] = (islower(area[0]) ? toupper(area[0]) : (area[0]));
  return (area);
}


x86 assembly (clang, -O0):
<Capitalise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2efd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c2 <Capitalise+0x82>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isupper@plt>
cmp    $0x0,%rax
je     1191 <Capitalise+0x51>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <Capitalise+0x5b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1157 <Capitalise+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movsbl 0x2e80(%rip),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11f6 <Capitalise+0xb6>
movsbl 0x2e6a(%rip),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
mov    %eax,-0x18(%rbp)
jmp    1200 <Capitalise+0xc0>
movsbl 0x2e53(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,0x2e47(%rip)
lea    0x2e40(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Capitalise>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1190 <Capitalise+0x50>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0x2ef8(%rip),%r14
jmp    1172 <Capitalise+0x32>
nopw   0x0(%rax,%rax,1)
mov    %al,(%r14)
add    $0x1,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1197 <Capitalise+0x57>
movsbl %al,%edi
call   1060 <isupper@plt>
mov    %rax,%rcx
movzbl -0x1(%rbx),%eax
test   %rcx,%rcx
je     1160 <Capitalise+0x20>
movsbl %al,%edi
call   1050 <tolower@plt>
jmp    1160 <Capitalise+0x20>
lea    0x2eb9(%rip),%r14
movb   $0x0,(%r14)
movsbl 0x2eae(%rip),%edi
call   1030 <islower@plt>
mov    %rax,%rcx
mov    0x2ea0(%rip),%al
test   %rcx,%rcx
je     11bd <Capitalise+0x7d>
movsbl %al,%edi
call   1040 <toupper@plt>
mov    %al,0x2e8d(%rip)
lea    0x2e86(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@Capitalise.area = internal global [1024 x i8] zeroinitializer
define i8* @Capitalise(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %22, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = call i64 @isupper(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 @tolower(i8 signext %15)
%17 = sext i8 %16 to i32
br label %22
18: ; preds = %8
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
br label %22
22: ; preds = %18, %13
%23 = phi i32 [ %17, %13 ], [ %21, %18 ]
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
store i8 %24, i8* %25
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %4
29: ; preds = %4
%30 = load i8*, i8** %3
store i8 0, i8* %30
%31 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
%32 = call i64 @islower(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
%36 = call signext i8 @toupper(i8 signext %35)
%37 = sext i8 %36 to i32
br label %41
38: ; preds = %29
%39 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
%40 = sext i8 %39 to i32
br label %41
41: ; preds = %38, %34
%42 = phi i32 [ %37, %34 ], [ %40, %38 ]
%43 = trunc i32 %42 to i8
store i8 %43, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
}

LLVM IR (-O2):
@Capitalise.area = internal global [1024 x i8] zeroinitializer
define i8* @Capitalise(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %13
%5 = phi i8 [ %17, %13 ], [ %2, %1 ]
%6 = phi i8* [ %15, %13 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0), %1 ]
%7 = phi i8* [ %16, %13 ], [ %0, %1 ]
%8 = tail call i64 @isupper(i8 signext %5)
%9 = icmp eq i64 %8, 0
%10 = load i8, i8* %7
br i1 %9, label %13, label %11
11: ; preds = %4
%12 = tail call signext i8 @tolower(i8 signext %10)
br label %13
13: ; preds = %4, %11
%14 = phi i8 [ %12, %11 ], [ %10, %4 ]
%15 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %14, i8* %6
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %13, %1
%20 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0), %1 ], [ %15, %13 ]
store i8 0, i8* %20
%21 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
%22 = tail call i64 @islower(i8 signext %21)
%23 = icmp eq i64 %22, 0
%24 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
br i1 %23, label %27, label %25
25: ; preds = %19
%26 = tail call signext i8 @toupper(i8 signext %24)
br label %27
27: ; preds = %19, %25
%28 = phi i8 [ %26, %25 ], [ %24, %19 ]
store i8 %28, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Capitalise.area, i64 0, i64 0)
}