#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*/ assert_equal_str(char *, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *pl_slice(char *, int, int);
void test_slice_negative_limit() {
  char the_string[] = "spam, eggs, and ham";
  char *ret_val;
  ret_val = pl_slice(the_string, 1, -3);
  assert_equal_str("pam, eggs, and ", ret_val, "test_slice_negative_limit",
                   "Test 1: The strings are not equal");
  free(ret_val);
  ret_val = pl_slice(the_string, 1, -10);
  assert_equal_str("pam, egg", ret_val, "test_slice_negative_limit",
                   "Test 2: The strings are not equal");
  free(ret_val);
  ret_val = pl_slice(the_string, 9, -10);
  assert_equal_str(NULL, ret_val, "test_slice_negative_limit",
                   "Test 3: The strings are not equal");
  ret_val = pl_slice(the_string, 0, -5);
  assert_equal_str("spam, eggs, an", ret_val, "test_slice_negative_limit",
                   "Test 4: The strings are not equal");
  free(ret_val);
}


x86 assembly (clang, -O0):
<test_slice_negative_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0xfffffffd,%edx
call   1050 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe9b(%rip),%rdi
lea    0xea4(%rip),%rdx
lea    0xeb7(%rip),%rcx
call   1040 <assert_equal_str@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0xfffffff6,%edx
call   1050 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xea9(%rip),%rdi
lea    0xe66(%rip),%rdx
lea    0xea4(%rip),%rcx
call   1040 <assert_equal_str@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    -0x20(%rbp),%rdi
mov    $0x9,%esi
mov    $0xfffffff6,%edx
call   1050 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2b(%rip),%rdx
lea    0xe8b(%rip),%rcx
call   1040 <assert_equal_str@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xfffffffb,%edx
call   1050 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe89(%rip),%rdi
lea    0xdf9(%rip),%rdx
lea    0xe8a(%rip),%rcx
call   1040 <assert_equal_str@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_slice_negative_limit>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movaps 0xec0(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6d6168,0x10(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xfffffffd,%edx
call   1050 <pl_slice@plt>
mov    %rax,%rbx
lea    0xea9(%rip),%rdi
lea    0xeb2(%rip),%r14
lea    0xec5(%rip),%rcx
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <assert_equal_str@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xfffffff6,%edx
call   1050 <pl_slice@plt>
mov    %rax,%rbx
lea    0xeb8(%rip),%rdi
lea    0xeba(%rip),%rcx
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <assert_equal_str@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x9,%esi
mov    $0xfffffff6,%edx
call   1050 <pl_slice@plt>
lea    0xeb0(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <assert_equal_str@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xfffffffb,%edx
call   1050 <pl_slice@plt>
mov    %rax,%rbx
lea    0xeac(%rip),%rdi
lea    0xeb4(%rip),%rcx
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <assert_equal_str@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_slice_negative_limit.the_string = [20 x i8] c"spam, eggs, and ham\00"
@.str = [16 x i8] c"pam, eggs, and \00"
@.str.1 = [26 x i8] c"test_slice_negative_limit\00"
@.str.2 = [34 x i8] c"Test 1: The strings are not equal\00"
@.str.3 = [9 x i8] c"pam, egg\00"
@.str.4 = [34 x i8] c"Test 2: The strings are not equal\00"
@.str.5 = [34 x i8] c"Test 3: The strings are not equal\00"
@.str.6 = [15 x i8] c"spam, eggs, an\00"
@.str.7 = [34 x i8] c"Test 4: The strings are not equal\00"
define void @test_slice_negative_limit() {
%1 = alloca [20 x i8]
%2 = alloca i8*
%3 = bitcast [20 x i8]* %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = call i8* @pl_slice(i8* %4, i32 1, i32 -3)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @assert_equal_str(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i32 @free(i8* %8)
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%11 = call i8* @pl_slice(i8* %10, i32 1, i32 -10)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @assert_equal_str(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%17 = call i8* @pl_slice(i8* %16, i32 9, i32 -10)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @assert_equal_str(i8* null, i8* %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%21 = call i8* @pl_slice(i8* %20, i32 0, i32 -5)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = call i32 @assert_equal_str(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
ret void
}

LLVM IR (-O2):
@__const.test_slice_negative_limit.the_string = [20 x i8] c"spam, eggs, and ham\00"
@.str = [16 x i8] c"pam, eggs, and \00"
@.str.1 = [26 x i8] c"test_slice_negative_limit\00"
@.str.2 = [34 x i8] c"Test 1: The strings are not equal\00"
@.str.3 = [9 x i8] c"pam, egg\00"
@.str.4 = [34 x i8] c"Test 2: The strings are not equal\00"
@.str.5 = [34 x i8] c"Test 3: The strings are not equal\00"
@.str.6 = [15 x i8] c"spam, eggs, an\00"
@.str.7 = [34 x i8] c"Test 4: The strings are not equal\00"
define void @test_slice_negative_limit() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i8* @pl_slice(i8* %2, i32 1, i32 -3)
%4 = call i32 @assert_equal_str(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @free(i8* %3)
%6 = call i8* @pl_slice(i8* %2, i32 1, i32 -10)
%7 = call i32 @assert_equal_str(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @free(i8* %6)
%9 = call i8* @pl_slice(i8* %2, i32 9, i32 -10)
%10 = call i32 @assert_equal_str(i8* null, i8* %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%11 = call i8* @pl_slice(i8* %2, i32 0, i32 -5)
%12 = call i32 @assert_equal_str(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%13 = call i32 @free(i8* %11)
ret void
}