#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 */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
void copy(char str1[100]) {
  char str2[100];
  int i;
  for (i = 0; str1[i] != '\0'; ++i) {
    str2[i] = str1[i];
  }
  str2[i] = '\0';
  printf("\nCopied string: ");
  puts(str2);
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     116c <copy+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x74(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1136 <copy+0x16>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
sub    $0x68,%rsp
mov    (%rdi),%al
test   %al,%al
je     1144 <copy+0x24>
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %al,(%rsp,%rcx,1)
movzbl 0x1(%rdi,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    1130 <copy+0x10>
mov    %ecx,%eax
jmp    1146 <copy+0x26>
xor    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1030 <puts@plt>
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0ACopied string: \00"
define void @copy(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %13
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%31 = call i32 @puts(i8* %30)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0ACopied string: \00"
define void @copy(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %10, %6 ], [ 0, %1 ]
%8 = phi i8 [ %12, %6 ], [ %4, %1 ]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %7
store i8 %8, i8* %9
%10 = add nuw nsw i64 %7, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = and i64 %10, 4294967295
br label %16
16: ; preds = %14, %1
%17 = phi i64 [ 0, %1 ], [ %15, %14 ]
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @puts(i8* %3)
ret void
}