#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 *StrCopy(char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
char *strcpy(char *, char const *);
void TestStrCopy() {
  const char str1[] = "test StrCopy";
  const char str2[] = "test StrCopy with Null\0 Following character "
                      "should not be printed";
  const char str_empty[] = "";
  char dest[100];
  char answer[100];
  char *res1, *res2;
  printf("===========================\n"
         "Test StrCopy\n"
         "===========================\n");
  printf("Test1:\n");
  res1 = StrCopy(dest, str1);
  res2 = strcpy(answer, str1);
  ((strcmp(res1, res2) == 0)) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%s]\n", res1);
  printf("String.h Answer: [%s]\n", res2);
  printf("\nTest2:\n");
  res1 = StrCopy(dest, str2);
  res2 = strcpy(answer, str2);
  ((strcmp(res1, res2) == 0)) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%s]\n", res1);
  printf("String.h Answer: [%s]\n", res2);
  printf("\nTest3:\n");
  res1 = StrCopy(dest, str_empty);
  res2 = strcpy(answer, str_empty);
  ((strcmp(res1, res2) == 0)) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%s]\n", res1);
  printf("String.h Answer: [%s]\n", res2);
  return;
}


x86 assembly (clang, -O0):
<TestStrCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    0xe8e(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe8c(%rip),%eax
mov    %eax,-0x5(%rbp)
mov    0xe87(%rip),%al
mov    %al,-0x1(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xf1d(%rip),%rsi
mov    $0x42,%edx
call   1080 <memcpy@plt>
lea    -0x51(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    -0xd(%rbp),%rsi
call   1030 <StrCopy@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
lea    -0xd(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1227 <TestStrCopy+0xc7>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1235 <TestStrCopy+0xd5>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x138(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x140(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <StrCopy@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12cb <TestStrCopy+0x16b>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d9 <TestStrCopy+0x179>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x138(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x140(%rbp),%rsi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    -0x51(%rbp),%rsi
call   1030 <StrCopy@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
lea    -0x51(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    136f <TestStrCopy+0x20f>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    137d <TestStrCopy+0x21d>
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x138(%rbp),%rsi
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x140(%rbp),%rsi
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestStrCopy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
movabs $0x79706f43727453,%rax
mov    %rax,0x15(%rsp)
movabs $0x7274532074736574,%rax
53 74 72
mov    %rax,0x10(%rsp)
movaps 0xf5a(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xf3e(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xf22(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf06(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movw   $0x64,0x60(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe79(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb2(%rip),%rdi
call   1050 <puts@plt>
lea    0x70(%rsp),%r14
lea    0x10(%rsp),%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <StrCopy@plt>
mov    %rax,%rbx
lea    0xe0(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xe8b(%rip),%rax
lea    0xe7d(%rip),%rbp
mov    %rbp,%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
lea    0xde0(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde3(%rip),%r13
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe32(%rip),%rdi
call   1050 <puts@plt>
lea    0x20(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <StrCopy@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    %rbp,%rdi
lea    0xe0e(%rip),%rax
cmove  %rax,%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd5(%rip),%rdi
call   1050 <puts@plt>
lea    0xf(%rsp),%r14
lea    0x70(%rsp),%rdi
mov    %r14,%rsi
call   1030 <StrCopy@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xdaa(%rip),%rax
cmove  %rax,%rbp
mov    %rbp,%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.TestStrCopy.str1 = [13 x i8] c"test StrCopy\00"
@__const.TestStrCopy.str2 = [66 x i8] c"test StrCopy with Null\00 Following character should not be printed\00"
@.str = [70 x i8] c"===========================\0ATest StrCopy\0A===========================\0A\00"
@.str.1 = [8 x i8] c"Test1:\0A\00"
@.str.2 = [10 x i8] c"Correct!\0A\00"
@.str.3 = [8 x i8] c"Wrong!\0A\00"
@.str.4 = [23 x i8] c"Your Answer: [%s]\0A\00"
@.str.5 = [23 x i8] c"String.h Answer: [%s]\0A\00"
@.str.6 = [9 x i8] c"\0ATest2:\0A\00"
@.str.7 = [9 x i8] c"\0ATest3:\0A\00"
define void @TestStrCopy() {
%1 = alloca [13 x i8]
%2 = alloca [66 x i8]
%3 = alloca [1 x i8]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = bitcast [13 x i8]* %1 to i8*
%9 = bitcast [66 x i8]* %2 to i8*
%10 = bitcast [1 x i8]* %3 to i8*
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%15 = call i8* @StrCopy(i8* %13, i8* %14)
store i8* %15, i8** %6
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%18 = call i8* @strcpy(i8* %16, i8* %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %27
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ %24, %23 ], [ %26, %25 ]
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%35 = getelementptr inbounds [66 x i8], [66 x i8]* %2, i64 0, i64 0
%36 = call i8* @StrCopy(i8* %34, i8* %35)
store i8* %36, i8** %6
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%38 = getelementptr inbounds [66 x i8], [66 x i8]* %2, i64 0, i64 0
%39 = call i8* @strcpy(i8* %37, i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %6
%41 = load i8*, i8** %7
%42 = call i64 @strcmp(i8* %40, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %27
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %48
46: ; preds = %27
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %44
%49 = phi i32 [ %45, %44 ], [ %47, %46 ]
%50 = load i8*, i8** %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%56 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%57 = call i8* @StrCopy(i8* %55, i8* %56)
store i8* %57, i8** %6
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%59 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%60 = call i8* @strcpy(i8* %58, i8* %59)
store i8* %60, i8** %7
%61 = load i8*, i8** %6
%62 = load i8*, i8** %7
%63 = call i64 @strcmp(i8* %61, i8* %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %48
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %69
67: ; preds = %48
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %65
%70 = phi i32 [ %66, %65 ], [ %68, %67 ]
%71 = load i8*, i8** %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %71)
%73 = load i8*, i8** %7
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %73)
ret void
}

LLVM IR (-O2):
@__const.TestStrCopy.str1 = [13 x i8] c"test StrCopy\00"
@__const.TestStrCopy.str2 = [66 x i8] c"test StrCopy with Null\00 Following character should not be printed\00"
@.str.4 = [23 x i8] c"Your Answer: [%s]\0A\00"
@.str.5 = [23 x i8] c"String.h Answer: [%s]\0A\00"
@str = [69 x i8] c"===========================\0ATest StrCopy\0A===========================\00"
@str.8 = [7 x i8] c"Test1:\00"
@str.10 = [8 x i8] c"\0ATest2:\00"
@str.12 = [8 x i8] c"\0ATest3:\00"
@str.13 = [7 x i8] c"Wrong!\00"
@str.16 = [9 x i8] c"Correct!\00"
define void @TestStrCopy() {
%1 = alloca [13 x i8]
%2 = alloca [66 x i8]
%3 = alloca [1 x i8]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [66 x i8], [66 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
%13 = call i8* @StrCopy(i8* %9, i8* %6)
%14 = call i8* @strcpy(i8* %10, i8* %6)
%15 = call i64 @strcmp(i8* %13, i8* %10)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%18 = call i32 @puts(i8* dereferenceable(1) %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%22 = call i8* @StrCopy(i8* %9, i8* %7)
%23 = call i8* @strcpy(i8* %10, i8* %7)
%24 = call i64 @strcmp(i8* %22, i8* %10)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%27 = call i32 @puts(i8* dereferenceable(1) %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%31 = call i8* @StrCopy(i8* %9, i8* %8)
%32 = call i8* @strcpy(i8* %10, i8* %8)
%33 = call i64 @strcmp(i8* %31, i8* %10)
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%36 = call i32 @puts(i8* dereferenceable(1) %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %10)
ret void
}