#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__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *Camelback2Pascal(const char *src) {
  if (src == NULL) {
    printf("src == NULL\n");
    return NULL;
  }
  int index = 0;
  int length = strlen(src);
  char *dst = (char *)malloc(length * 2);
  memset(dst, 0, length * 2);
  strcpy(dst, src);
  dst[0] = src[0] - 32;
  return dst;
}


x86 assembly (clang, -O0):
<Camelback2Pascal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <Camelback2Pascal+0x30>
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <Camelback2Pascal+0x8a>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
shl    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
shl    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x20,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Camelback2Pascal>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     118e <Camelback2Pascal+0x3e>
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    (%rax,%rax,1),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%r14),%al
add    $0xe0,%al
mov    %al,(%rbx)
jmp    119c <Camelback2Pascal+0x4c>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"src == NULL\0A\00"
define i8* @Camelback2Pascal(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %34
11: ; preds = %1
store i32 0, i32* %4
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 2
%21 = call i32 @memset(i8* %18, i32 0, i32 %20)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 32
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 %30, i8* %32
%33 = load i8*, i8** %6
store i8* %33, i8** %2
br label %34
34: ; preds = %11, %9
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@str = [12 x i8] c"src == NULL\00"
define i8* @Camelback2Pascal(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %14
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = shl nsw i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @memset(i8* %9, i32 0, i32 %7)
%11 = tail call i32 @strcpy(i8* %9, i8* %0)
%12 = load i8, i8* %0
%13 = add i8 %12, -32
store i8 %13, i8* %9
br label %14
14: ; preds = %5, %3
%15 = phi i8* [ null, %3 ], [ %9, %5 ]
ret i8* %15
}