#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(size_t);
size_t strlen(char *);
char *pickString(char str[]) {
  size_t len = strlen(str);
  unsigned int t = 0;
  char *final_string = (char *)malloc((len + 2) * sizeof(char));
  while (t <= len) {
    final_string[t] = str[t];
    t++;
  }
  if (t > 0) {
    final_string[t] = '\0';
    return final_string;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<pickString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
shl    $0x0,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
ja     1184 <pickString+0x64>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <pickString+0x35>
cmpl   $0x0,-0x1c(%rbp)
jbe    11a6 <pickString+0x86>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <pickString+0x8e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pickString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x2(%rax),%rdi
call   1040 <malloc@plt>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rcx,1),%edx
mov    %dl,(%rax,%rcx,1)
add    $0x1,%ecx
cmp    %rcx,%rbx
jae    1140 <pickString+0x20>
test   %ecx,%ecx
je     115c <pickString+0x3c>
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    115e <pickString+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @pickString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
store i32 0, i32* %5
%9 = load i64, i64* %4
%10 = add i64 %9, 2
%11 = mul i64 %10, 1
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
br label %14
14: ; preds = %19, %1
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = load i64, i64* %4
%18 = icmp ule i64 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %6
%26 = load i32, i32* %5
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i32, i32* %5
%30 = add i32 %29, 1
store i32 %30, i32* %5
br label %14
31: ; preds = %14
%32 = load i32, i32* %5
%33 = icmp ugt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %6
store i8* %39, i8** %2
br label %41
40: ; preds = %31
store i8* null, i8** %2
br label %41
41: ; preds = %40, %34
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @pickString(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 2
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
br label %6
6: ; preds = %1, %6
%7 = phi i64 [ 0, %1 ], [ %13, %6 ]
%8 = trunc i64 %7 to i32
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 %10, i8* %11
%12 = add i32 %8, 1
%13 = zext i32 %12 to i64
%14 = icmp ult i64 %2, %13
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = icmp eq i32 %12, 0
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = zext i32 %12 to i64
%19 = getelementptr inbounds i8, i8* %5, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15, %17
%21 = phi i8* [ %5, %17 ], [ null, %15 ]
ret i8* %21
}