#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*/ ctest_assert_true(int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strings_free(char *);
char *strings_new(char *);
int test_strings_new() {
  {
    char *src = "This is a string..";
    char *str = strings_new(src);
    char *assert_message = "Testing strings copy for regular string..";
    int assert_result = (strcmp(str, src) == 0) ? 1 : 0;
    ctest_assert_true(assert_result, assert_message);
    strings_free(str);
  }
  {
    char *src = "";
    char *str = strings_new(src);
    char *assert_message = "Testing string copy for empty string..";
    int assert_result = (strcmp(str, src) == 0) ? 1 : 0;
    ctest_assert_true(assert_result, assert_message);
    strings_free(str);
  }
  {
    char *src = NULL;
    char *str = strings_new(src);
    char *assert_message = "Testing string copy for NULL..";
    int assert_result = (str == NULL) ? 1 : 0;
    ctest_assert_true(assert_result, assert_message);
    strings_free(str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_strings_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strings_new@plt>
mov    %rax,-0x10(%rbp)
lea    0xeac(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <ctest_assert_true@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strings_free@plt>
lea    0xeda(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strings_new@plt>
mov    %rax,-0x30(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1060 <ctest_assert_true@plt>
mov    -0x30(%rbp),%rdi
call   1030 <strings_free@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strings_new@plt>
mov    %rax,-0x50(%rbp)
lea    0xe4e(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
call   1060 <ctest_assert_true@plt>
mov    -0x50(%rbp),%rdi
call   1030 <strings_free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strings_new>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
call   1040 <strings_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
lea    0xea2(%rip),%rsi
call   1060 <ctest_assert_true@plt>
mov    %rbx,%rdi
call   1030 <strings_free@plt>
lea    0xefd(%rip),%r14
mov    %r14,%rdi
call   1040 <strings_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
lea    0xe92(%rip),%rsi
call   1060 <ctest_assert_true@plt>
mov    %rbx,%rdi
call   1030 <strings_free@plt>
xor    %edi,%edi
call   1040 <strings_new@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
sete   %dil
lea    0xe92(%rip),%rsi
call   1060 <ctest_assert_true@plt>
mov    %rbx,%rdi
call   1030 <strings_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"This is a string..\00"
@.str.1 = [42 x i8] c"Testing strings copy for regular string..\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [39 x i8] c"Testing string copy for empty string..\00"
@.str.4 = [31 x i8] c"Testing string copy for NULL..\00"
define i32 @test_strings_new() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %1
%13 = load i8*, i8** %1
%14 = call i8* @strings_new(i8* %13)
store i8* %14, i8** %2
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8** %3
%15 = load i8*, i8** %2
%16 = load i8*, i8** %1
%17 = call i64 @strcmp(i8* %15, i8* %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 1, i32 0
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = call i32 @ctest_assert_true(i32 %21, i8* %22)
%24 = load i8*, i8** %2
%25 = call i32 @strings_free(i8* %24)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %5
%26 = load i8*, i8** %5
%27 = call i8* @strings_new(i8* %26)
store i8* %27, i8** %6
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8** %7
%28 = load i8*, i8** %6
%29 = load i8*, i8** %5
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = load i8*, i8** %7
%36 = call i32 @ctest_assert_true(i32 %34, i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @strings_free(i8* %37)
store i8* null, i8** %9
%39 = load i8*, i8** %9
%40 = call i8* @strings_new(i8* %39)
store i8* %40, i8** %10
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8** %11
%41 = load i8*, i8** %10
%42 = icmp eq i8* %41, null
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 1, i32 0
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = load i8*, i8** %11
%47 = call i32 @ctest_assert_true(i32 %45, i8* %46)
%48 = load i8*, i8** %10
%49 = call i32 @strings_free(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"This is a string..\00"
@.str.1 = [42 x i8] c"Testing strings copy for regular string..\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [39 x i8] c"Testing string copy for empty string..\00"
@.str.4 = [31 x i8] c"Testing string copy for NULL..\00"
define i32 @test_strings_new() {
%1 = tail call i8* @strings_new(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @ctest_assert_true(i32 %4, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @strings_free(i8* %1)
%7 = tail call i8* @strings_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @ctest_assert_true(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @strings_free(i8* %7)
%13 = tail call i8* @strings_new(i8* null)
%14 = icmp eq i8* %13, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @ctest_assert_true(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32 @strings_free(i8* %13)
ret i32 0
}