#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 */
char *calloc(int /*<<< orphan*/, size_t);
size_t strlen(char *);
char *copyString(char *inputString) {
  char *outputString;
  outputString = calloc(0, strlen(inputString));
  int i = 0;
  for (i = 0; i < strlen(inputString); i++) {
    outputString[i] = inputString[i];
  }
  outputString[strlen(outputString)] = '\0';
  return outputString;
}


x86 assembly (clang, -O0):
<copyString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rsi
xor    %edi,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    1196 <copyString+0x76>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <copyString+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %edi,%edi
mov    %rax,%rsi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    (%r15),%al
test   %al,%al
je     117a <copyString+0x5a>
mov    %al,(%r14)
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%rax
jb     117a <copyString+0x5a>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %rbx,%rax
ja     1160 <copyString+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @copyString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = call i8* @calloc(i32 0, i64 %6)
store i8* %7, i8** %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %14
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %8
27: ; preds = %8
%28 = load i8*, i8** %3
%29 = load i8*, i8** %3
%30 = call i64 @strlen(i8* %29)
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @copyString(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i8* @calloc(i32 0, i64 %2)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
store i8 %4, i8* %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = icmp ugt i64 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %6, %9
%10 = phi i64 [ %14, %9 ], [ 1, %6 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 %12, i8* %13
%14 = add nuw nsw i64 %10, 1
%15 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%16 = icmp ugt i64 %15, %14
br i1 %16, label %9, label %17
17: ; preds = %9, %6, %1
%18 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%19 = getelementptr inbounds i8, i8* %3, i64 %18
store i8 0, i8* %19
ret i8* %3
}