#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__ isLowerCase(char);
scalar_t__ isUpperCase(char);
scalar_t__ malloc(int);
int strlen(char *);
char *getStringFormat(char *line) {
  char *format = (char *)malloc((strlen(line) + 1) * sizeof(char));
  int i;
  for (i = 0; i < strlen(line); i++) {
    char c = *(line + i);
    if (isUpperCase(c)) {
      *(format + i) = 'C';
    } else if (isLowerCase(c)) {
      *(format + i) = 'c';
    } else {
      *(format + i) = c;
    }
  }
  *(format + strlen(line)) = '\0';
  return format;
}


x86 assembly (clang, -O0):
<getStringFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1208 <getStringFormat+0xc8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1060 <isUpperCase@plt>
cmp    $0x0,%rax
je     11be <getStringFormat+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x43,(%rax,%rcx,1)
jmp    11f5 <getStringFormat+0xb5>
movsbl -0x15(%rbp),%edi
call   1040 <isLowerCase@plt>
cmp    $0x0,%rax
je     11e2 <getStringFormat+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x63,(%rax,%rcx,1)
jmp    11f0 <getStringFormat+0xb0>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11f5 <getStringFormat+0xb5>
jmp    11fa <getStringFormat+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <getStringFormat+0x30>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStringFormat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b6 <getStringFormat+0x76>
xor    %ebx,%ebx
jmp    1188 <getStringFormat+0x48>
nopl   0x0(%rax,%rax,1)
movb   $0x43,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11b6 <getStringFormat+0x76>
movzbl (%r15,%rbx,1),%r12d
movsbl %r12b,%ebp
mov    %ebp,%edi
call   1060 <isUpperCase@plt>
test   %rax,%rax
jne    1170 <getStringFormat+0x30>
mov    %ebp,%edi
call   1040 <isLowerCase@plt>
test   %rax,%rax
je     11b0 <getStringFormat+0x70>
movb   $0x63,(%r14,%rbx,1)
jmp    1175 <getStringFormat+0x35>
mov    %r12b,(%r14,%rbx,1)
jmp    1175 <getStringFormat+0x35>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getStringFormat(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
store i32 0, i32* %4
br label %14
14: ; preds = %50, %1
%15 = load i32, i32* %4
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %53
19: ; preds = %14
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %5
%25 = load i8, i8* %5
%26 = call i64 @isUpperCase(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 67, i8* %32
br label %49
33: ; preds = %19
%34 = load i8, i8* %5
%35 = call i64 @isLowerCase(i8 signext %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 99, i8* %41
br label %48
42: ; preds = %33
%43 = load i8, i8* %5
%44 = load i8*, i8** %3
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
br label %48
48: ; preds = %42, %37
br label %49
49: ; preds = %48, %28
br label %50
50: ; preds = %49
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %14
53: ; preds = %14
%54 = load i8*, i8** %3
%55 = load i8*, i8** %2
%56 = call i32 @strlen(i8* %55)
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %3
ret i8* %59
}

LLVM IR (-O2):
define i8* @getStringFormat(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %1, %22
%9 = phi i64 [ %23, %22 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isUpperCase(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 67, i8* %15
br label %22
16: ; preds = %8
%17 = tail call i64 @isLowerCase(i8 signext %11)
%18 = icmp eq i64 %17, 0
%19 = getelementptr inbounds i8, i8* %5, i64 %9
br i1 %18, label %21, label %20
20: ; preds = %16
store i8 99, i8* %19
br label %22
21: ; preds = %16
store i8 %11, i8* %19
br label %22
22: ; preds = %20, %21, %14
%23 = add nuw nsw i64 %9, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %8, label %27
27: ; preds = %22, %1
%28 = tail call i32 @strlen(i8* %0)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %5, i64 %29
store i8 0, i8* %30
ret i8* %5
}