#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 *parse_alloc(int);
int strlen(char const *);
char *parse_string_dup(const char *str) {
  char *str2 = parse_alloc(sizeof(char) * (strlen(str) + 1));
  for (size_t i = 0; i < strlen(str) + 1; i++)
    str2[i] = str[i];
  return str2;
}


x86 assembly (clang, -O0):
<parse_string_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <parse_alloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    119e <parse_string_dup+0x7e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <parse_string_dup+0x31>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_string_dup>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <parse_alloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0xffffffff,%eax
je     116f <parse_string_dup+0x4f>
xor    %ebx,%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>
add    $0x1,%eax
cltq
cmp    %rax,%rbx
jb     1150 <parse_string_dup+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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