#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 *malloc(int);
int strlen(char *);
void copiaStr(char *a, char **b) {
  *b = malloc(strlen(a));
  for (int i = 0; i < strlen(a); i++)
    *(b[i]) = a[i];
}


x86 assembly (clang, -O0):
<copiaStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1194 <copiaStr+0x74>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <copiaStr+0x31>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copiaStr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    116e <copiaStr+0x4e>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    (%r14,%rbx,8),%rcx
mov    %al,(%rcx)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <copiaStr+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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