#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(int /*<<< orphan*/ *, char *, char *,
                                    char *);
char *pl_slice(char *, int, int);
void test_slice_negative_offset() {
  char the_string[] = "spam, eggs, and ham";
  char *ret_val;
  ret_val = pl_slice(the_string, -3, 9);
  assert_equal_str(NULL, ret_val, "test_slice_negative_offset",
                   "Test 1: The ret_val is not empty.");
  ret_val = pl_slice(the_string, -1, 9);
  assert_equal_str(NULL, ret_val, "test_slice_negative_offset",
                   "Test 2: The ret_val is not empty.");
  ret_val = pl_slice(the_string, -9, 9);
  assert_equal_str(NULL, ret_val, "test_slice_negative_offset",
                   "Test 3: The ret_val is not empty.");
  ret_val = pl_slice(the_string, -1, 3);
  assert_equal_str(NULL, ret_val, "test_slice_negative_offset",
                   "Test 4: The ret_val is not empty.");
  ret_val = pl_slice(the_string, -4, 1);
  assert_equal_str(NULL, ret_val, "test_slice_negative_offset",
                   "Test 5: The ret_val is not empty.");
}


x86 assembly (clang, -O0):
<test_slice_negative_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xfffffffd,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xea7(%rip),%rdx
lea    0xebb(%rip),%rcx
call   1030 <assert_equal_str@plt>
lea    -0x20(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe75(%rip),%rdx
lea    0xeab(%rip),%rcx
call   1030 <assert_equal_str@plt>
lea    -0x20(%rbp),%rdi
mov    $0xfffffff7,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe43(%rip),%rdx
lea    0xe9b(%rip),%rcx
call   1030 <assert_equal_str@plt>
lea    -0x20(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x3,%edx
call   1040 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe11(%rip),%rdx
lea    0xe8b(%rip),%rcx
call   1030 <assert_equal_str@plt>
lea    -0x20(%rbp),%rdi
mov    $0xfffffffc,%esi
mov    $0x1,%edx
call   1040 <pl_slice@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xddf(%rip),%rdx
lea    0xe7b(%rip),%rcx
call   1030 <assert_equal_str@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_slice_negative_offset>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x6d6168,0x10(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xfffffffd,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
lea    0xebe(%rip),%r14
lea    0xed2(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <assert_equal_str@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
lea    0xece(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <assert_equal_str@plt>
mov    %rbx,%rdi
mov    $0xfffffff7,%esi
mov    $0x9,%edx
call   1040 <pl_slice@plt>
lea    0xeca(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <assert_equal_str@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x3,%edx
call   1040 <pl_slice@plt>
lea    0xec6(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <assert_equal_str@plt>
mov    %rbx,%rdi
mov    $0xfffffffc,%esi
mov    $0x1,%edx
call   1040 <pl_slice@plt>
lea    0xec2(%rip),%rcx
xor    %edi,%edi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <assert_equal_str@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_slice_negative_offset.the_string = [20 x i8] c"spam, eggs, and ham\00"
@.str = [27 x i8] c"test_slice_negative_offset\00"
@.str.1 = [34 x i8] c"Test 1: The ret_val is not empty.\00"
@.str.2 = [34 x i8] c"Test 2: The ret_val is not empty.\00"
@.str.3 = [34 x i8] c"Test 3: The ret_val is not empty.\00"
@.str.4 = [34 x i8] c"Test 4: The ret_val is not empty.\00"
@.str.5 = [34 x i8] c"Test 5: The ret_val is not empty.\00"
define void @test_slice_negative_offset() {
%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 -3, i32 9)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @assert_equal_str(i32* null, i8* %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%9 = call i8* @pl_slice(i8* %8, i32 -1, i32 9)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @assert_equal_str(i32* null, i8* %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%13 = call i8* @pl_slice(i8* %12, i32 -9, i32 9)
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @assert_equal_str(i32* null, i8* %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%17 = call i8* @pl_slice(i8* %16, i32 -1, i32 3)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @assert_equal_str(i32* null, i8* %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, 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 -4, i32 1)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = call i32 @assert_equal_str(i32* null, i8* %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.test_slice_negative_offset.the_string = [20 x i8] c"spam, eggs, and ham\00"
@.str = [27 x i8] c"test_slice_negative_offset\00"
@.str.1 = [34 x i8] c"Test 1: The ret_val is not empty.\00"
@.str.2 = [34 x i8] c"Test 2: The ret_val is not empty.\00"
@.str.3 = [34 x i8] c"Test 3: The ret_val is not empty.\00"
@.str.4 = [34 x i8] c"Test 4: The ret_val is not empty.\00"
@.str.5 = [34 x i8] c"Test 5: The ret_val is not empty.\00"
define void @test_slice_negative_offset() {
%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 -3, i32 9)
%4 = call i32 @assert_equal_str(i32* null, i8* %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i8* @pl_slice(i8* %2, i32 -1, i32 9)
%6 = call i32 @assert_equal_str(i32* null, i8* %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%7 = call i8* @pl_slice(i8* %2, i32 -9, i32 9)
%8 = call i32 @assert_equal_str(i32* null, i8* %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%9 = call i8* @pl_slice(i8* %2, i32 -1, i32 3)
%10 = call i32 @assert_equal_str(i32* null, i8* %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%11 = call i8* @pl_slice(i8* %2, i32 -4, i32 1)
%12 = call i32 @assert_equal_str(i32* null, i8* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
ret void
}