#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 */
struct SmazBranch {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ hexDump(char *, char **, int);
int /*<<< orphan*/ printf(char *, ...);
struct SmazBranch *smaz_build_trie();
int smaz_compress(struct SmazBranch *, char *, int, char *, int);
int smaz_decompress(char *, int, char *, int);
int /*<<< orphan*/ smaz_free_trie(struct SmazBranch *);
int strlen(char *);
void test_null_term() {
  char comp_out[256];
  char decomp_out[256];
  char no_null_str[4] = "test";
  char null_term_str[] = "test";
  int comprlen = 0;
  int decomprlen = 0;
  struct SmazBranch *trie;
  trie = smaz_build_trie();
  comprlen = smaz_compress(trie, no_null_str, 4, comp_out, 256);
  decomprlen = smaz_decompress(comp_out, comprlen, decomp_out, 256);
  if (decomprlen != 4) {
    printf("Error: Expected return size: %d, got %d\n", 4, decomprlen);
    exit(1);
  }
  if (decomp_out[3] != 't') {
    printf("Error: Incorrect final char on string: %c, expected %c\n",
           decomp_out[3], 't');
    exit(1);
  }
  comprlen = smaz_compress(trie, null_term_str, strlen(null_term_str) + 1,
                           comp_out, 256);
  decomprlen = smaz_decompress(comp_out, comprlen, decomp_out, 256);
  if (decomprlen != 5) {
    printf("Error: Expected return size: %d, got %d\n", 5, decomprlen);
    hexDump("out", &decomp_out, decomprlen);
    exit(1);
  }
  if (decomp_out[4] != 0) {
    printf("Error: Incorrect final char on string: %c, expected \\0\n",
           decomp_out[4]);
    exit(1);
  }
  smaz_free_trie(trie);
  printf("TEST PASSED :)\n");
}


x86 assembly (clang, -O0):
<test_null_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    0xe6f(%rip),%eax
mov    %eax,-0x204(%rbp)
mov    0xe67(%rip),%eax
mov    %eax,-0x209(%rbp)
mov    0xe5f(%rip),%al
mov    %al,-0x205(%rbp)
movl   $0x0,-0x210(%rbp)
movl   $0x0,-0x214(%rbp)
mov    $0x0,%al
call   1090 <smaz_build_trie@plt>
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rdi
lea    -0x204(%rbp),%rsi
lea    -0x100(%rbp),%rcx
mov    $0x4,%edx
mov    $0x100,%r8d
call   1060 <smaz_compress@plt>
mov    %eax,-0x210(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x210(%rbp),%esi
lea    -0x200(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <smaz_decompress@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x4,-0x214(%rbp)
je     1250 <test_null_term+0xd0>
mov    -0x214(%rbp),%edx
lea    0xdcf(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movsbl -0x1fd(%rbp),%eax
cmp    $0x74,%eax
je     1284 <test_null_term+0x104>
movsbl -0x1fd(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x74,%edx
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
lea    -0x209(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x209(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x230(%rbp),%rdi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x100(%rbp),%rcx
mov    $0x100,%r8d
call   1060 <smaz_compress@plt>
mov    %eax,-0x210(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x210(%rbp),%esi
lea    -0x200(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <smaz_decompress@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x5,-0x214(%rbp)
je     1344 <test_null_term+0x1c4>
mov    -0x214(%rbp),%edx
lea    0xcf4(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x200(%rbp),%rsi
mov    -0x214(%rbp),%edx
lea    0xd35(%rip),%rdi
call   1070 <hexDump@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movsbl -0x1fc(%rbp),%eax
cmp    $0x0,%eax
je     1373 <test_null_term+0x1f3>
movsbl -0x1fc(%rbp),%esi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x220(%rbp),%rdi
call   1030 <smaz_free_trie@plt>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_null_term>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
movl   $0x74736574,0xc(%rsp)
74
movb   $0x0,0x8(%rsp)
movl   $0x74736574,0x4(%rsp)
74
xor    %eax,%eax
call   10a0 <smaz_build_trie@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
lea    0x110(%rsp),%rbp
mov    %rax,%rdi
mov    $0x4,%edx
mov    %rbp,%rcx
mov    $0x100,%r8d
call   1070 <smaz_compress@plt>
lea    0x10(%rsp),%rdx
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x100,%ecx
call   1090 <smaz_decompress@plt>
cmp    $0x4,%eax
jne    127a <test_null_term+0xea>
movsbl 0x13(%rsp),%esi
cmp    $0x74,%esi
jne    128a <test_null_term+0xfa>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x110(%rsp),%r14
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rcx
mov    $0x100,%r8d
call   1070 <smaz_compress@plt>
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x100,%ecx
call   1090 <smaz_decompress@plt>
cmp    $0x5,%eax
jne    12a7 <test_null_term+0x117>
movsbl 0x14(%rsp),%esi
test   %esi,%esi
jne    12db <test_null_term+0x14b>
mov    %rbx,%rdi
call   1030 <smaz_free_trie@plt>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd84(%rip),%rdi
mov    $0x4,%esi
mov    %eax,%edx
jmp    1296 <test_null_term+0x106>
lea    0xd9d(%rip),%rdi
mov    $0x74,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
lea    0xd55(%rip),%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda1(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %ebp,%edx
call   1080 <hexDump@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.SmazBranch = type { i32 }
@__const.test_null_term.no_null_str = [4 x i8] c"test"
@__const.test_null_term.null_term_str = [5 x i8] c"test\00"
@.str = [41 x i8] c"Error: Expected return size: %d, got %d\0A\00"
@.str.1 = [56 x i8] c"Error: Incorrect final char on string: %c, expected %c\0A\00"
@.str.2 = [4 x i8] c"out\00"
@.str.3 = [56 x i8] c"Error: Incorrect final char on string: %c, expected \\0\0A\00"
@.str.4 = [16 x i8] c"TEST PASSED :)\0A\00"
define void @test_null_term() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca [4 x i8]
%4 = alloca [5 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.SmazBranch*
%8 = bitcast [4 x i8]* %3 to i8*
%9 = bitcast [5 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
%10 = call %struct.SmazBranch* (...) @smaz_build_trie()
store %struct.SmazBranch* %10, %struct.SmazBranch** %7
%11 = load %struct.SmazBranch*, %struct.SmazBranch** %7
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%14 = call i32 @smaz_compress(%struct.SmazBranch* %11, i8* %12, i32 4, i8* %13, i32 256)
store i32 %14, i32* %5
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* %5
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i32 @smaz_decompress(i8* %15, i32 %16, i8* %17, i32 256)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %25
21: ; preds = %0
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 4, i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 116
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 116)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = load %struct.SmazBranch*, %struct.SmazBranch** %7
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %40, 1
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%43 = call i32 @smaz_compress(%struct.SmazBranch* %37, i8* %38, i32 %41, i8* %42, i32 256)
store i32 %43, i32* %5
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%45 = load i32, i32* %5
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%47 = call i32 @smaz_decompress(i8* %44, i32 %45, i8* %46, i32 256)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp ne i32 %48, 5
br i1 %49, label %50, label %57
50: ; preds = %36
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 5, i32 %51)
%53 = bitcast [256 x i8]* %2 to i8**
%54 = load i32, i32* %6
%55 = call i32 @hexDump(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %53, i32 %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %36
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %57
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %57
%69 = load %struct.SmazBranch*, %struct.SmazBranch** %7
%70 = call i32 @smaz_free_trie(%struct.SmazBranch* %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.SmazBranch = type { i32 }
@__const.test_null_term.null_term_str = [5 x i8] c"test\00"
@.str = [41 x i8] c"Error: Expected return size: %d, got %d\0A\00"
@.str.1 = [56 x i8] c"Error: Incorrect final char on string: %c, expected %c\0A\00"
@.str.2 = [4 x i8] c"out\00"
@.str.3 = [56 x i8] c"Error: Incorrect final char on string: %c, expected \\0\0A\00"
@str = [15 x i8] c"TEST PASSED :)\00"
define void @test_null_term() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
store i32 1953719668, i32* %3
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%9 = tail call %struct.SmazBranch* (...) @smaz_build_trie()
%10 = call i32 @smaz_compress(%struct.SmazBranch* %9, i8* %7, i32 4, i8* %5, i32 256)
%11 = call i32 @smaz_decompress(i8* %5, i32 %10, i8* %6, i32 256)
%12 = icmp eq i32 %11, 4
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 4, i32 %11)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 116
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = sext i8 %18 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 116)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = call i32 @strlen(i8* %8)
%26 = add nsw i32 %25, 1
%27 = call i32 @smaz_compress(%struct.SmazBranch* %9, i8* %8, i32 %26, i8* %5, i32 256)
%28 = call i32 @smaz_decompress(i8* %5, i32 %27, i8* %6, i32 256)
%29 = icmp eq i32 %28, 5
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 5, i32 %28)
%32 = bitcast [256 x i8]* %2 to i8**
%33 = call i32 @hexDump(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %32, i32 %28)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %24
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = sext i8 %37 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %35
%44 = call i32 @smaz_free_trie(%struct.SmazBranch* %9)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret void
}