#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*/ exit(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *random_string(int);
scalar_t__ strcmp(char *, char *);
char *strcpy(char *, char *);
int main(void) {
  char *ret_str;
  int i;
  for (i = 0; i < 50000; i += 2000) {
    char *sample_str_1;
    char *sample_str_2 = malloc(i + 1);
    if (sample_str_2 == NULL) {
      printf("strcpy/1-1.c"
             "Failed to allocate memory\n");
      exit(2);
    }
    sample_str_1 = random_string(i);
    ret_str = strcpy(sample_str_2, sample_str_1);
    if (strcmp(sample_str_1, sample_str_2) != 0) {
      printf("strcpy/1-1.c"
             " Test Failed, string copy failed. "
             "Expected string: %s, But got: %s\n",
             sample_str_1, sample_str_2);
      exit(1);
    } else if (ret_str != sample_str_2) {
      printf("strcpy/1-1.c"
             " Test Failed, return is not as expected. "
             "Expected return: %p, But obtained: %p\n",
             sample_str_2, ret_str);
      exit(1);
    }
    free(sample_str_1);
    free(sample_str_2);
  }
  printf("strcpy/1-1.c"
         " Test Passed, string copied successfully\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xc350,-0x14(%rbp)
jge    126e <main+0xfe>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c5 <main+0x55>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <random_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1219 <main+0xa9>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1247 <main+0xd7>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    124c <main+0xdc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x7d0,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x16>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xfffff830,%r15d
nopl   0x0(%rax,%rax,1)
lea    0x7d1(%r15),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     11fd <main+0x7d>
mov    %rax,%r14
add    $0x7d0,%r15d
mov    %r15d,%edi
call   1060 <random_string@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1213 <main+0x93>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
cmp    $0xbb80,%r15d
jb     1190 <main+0x10>
lea    0xe5f(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe81(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xde6(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"strcpy/1-1.cFailed to allocate memory\0A\00"
@.str.1 = [80 x i8] c"strcpy/1-1.c Test Failed, string copy failed. Expected string: %s, But got: %s\0A\00"
@.str.2 = [92 x i8] c"strcpy/1-1.c Test Failed, return is not as expected. Expected return: %p, But obtained: %p\0A\00"
@.str.3 = [54 x i8] c"strcpy/1-1.c Test Passed, string copied successfully\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %48, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 50000
br i1 %8, label %9, label %51
9: ; preds = %6
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = load i32, i32* %3
%20 = call i8* @random_string(i32 %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = call i8* @strcpy(i8* %21, i8* %22)
store i8* %23, i8** %2
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %18
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = load i8*, i8** %2
%35 = load i8*, i8** %5
%36 = icmp ne i8* %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = load i8*, i8** %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
br label %43
43: ; preds = %42
%44 = load i8*, i8** %4
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %43
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 2000
store i32 %50, i32* %3
br label %6
51: ; preds = %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [80 x i8] c"strcpy/1-1.c Test Failed, string copy failed. Expected string: %s, But got: %s\0A\00"
@str = [53 x i8] c"strcpy/1-1.c Test Passed, string copied successfully\00"
@str.4 = [38 x i8] c"strcpy/1-1.cFailed to allocate memory\00"
define i32 @main() {
br label %1
1: ; preds = %0, %17
%2 = phi i32 [ 0, %0 ], [ %20, %17 ]
%3 = or i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %1
%10 = tail call i8* @random_string(i32 %2)
%11 = tail call i8* @strcpy(i8* %4, i8* dereferenceable(1) %10)
%12 = tail call i64 @strcmp(i8* %10, i8* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %4)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = tail call i32 @free(i8* %10)
%19 = tail call i32 @free(i8* %4)
%20 = add nuw nsw i32 %2, 2000
%21 = icmp ult i32 %2, 48000
br i1 %21, label %1, label %22
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
}