#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*/ *TrimSpace(char const *, int, char *, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(int /*<<< orphan*/ *, char const *);
int strlen(char const *);
void TestTrim() {
  char buf[256 + 1];
  const char *str1 = "   This is a test str   ";
  const char *str2 = "   This is a test str";
  const char *str3 = "This is a test str   ";
  const char *str4 = "This is a test str";
  const char *rString = "This is a test str";
  memset(buf, 0, 256 + 1);
  printf("\n-------------------------------------------------------------------"
         "---------\n");
  printf("  Test trim functions\n");
  printf("---------------------------------------------------------------------"
         "-------\n");
  {
    printf("Trim start and end spaces of \"%s\": ", str1);
    assert(strcmp(TrimSpace(str1, strlen(str1), buf, 256), rString) == 0);
    printf("[OK]\n");
  };
  {
    printf("Trim start and end spaces of \"%s\": ", str2);
    assert(strcmp(TrimSpace(str2, strlen(str2), buf, 256), rString) == 0);
    printf("[OK]\n");
  };
  {
    printf("Trim start and end spaces of \"%s\": ", str3);
    assert(strcmp(TrimSpace(str3, strlen(str3), buf, 256), rString) == 0);
    printf("[OK]\n");
  };
  {
    printf("Trim start and end spaces of \"%s\": ", str4);
    assert(strcmp(TrimSpace(str4, strlen(str4), buf, 256), rString) == 0);
    printf("[OK]\n");
  };
  {
    printf("Trim start and end spaces of \"%s\": ",
           "   ONELONGSTRINGOFJUNK   ");
    assert(strcmp(TrimSpace("   ONELONGSTRINGOFJUNK   ",
                            strlen("   ONELONGSTRINGOFJUNK   "), buf, 256),
                  "ONELONGSTRINGOFJUNK") == 0);
    printf("[OK]\n");
  };
  printf("\n");
  {
    printf("Attempt to trim NULL string: ");
    assert(TrimSpace(NULL, 100, buf, 256) == NULL);
    printf("[OK]\n");
  };
  {
    printf("Attempt to trim string with 0 size: ");
    assert(TrimSpace(str1, 0, buf, 256) == NULL);
    printf("[OK]\n");
  };
  {
    printf("Attempt to trim string with NULL buffer: ");
    assert(TrimSpace(str1, strlen(str1), NULL, 256) == NULL);
    printf("[OK]\n");
  };
  {
    printf("Attempt to trim string with too small buffer: ");
    assert(TrimSpace(str1, strlen(str1), buf, 3) == NULL);
    printf("[OK]\n");
  };
  {
    printf("Cannot trim an empty string: ");
    assert(TrimSpace("", 0, buf, 256) == NULL);
    printf("[OK]\n");
  };
  {
    printf("Cannot trim a NULL string: ");
    assert(TrimSpace(NULL, 100, buf, 256) == NULL);
    printf("[OK]\n");
  };
  printf("---------------------------------------------------------------------"
         "-------\n");
  printf("  Done.\n");
  printf("---------------------------------------------------------------------"
         "-------\n\n");
}


x86 assembly (clang, -O0):
<TestTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
lea    0xe8e(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x120(%rbp)
lea    0xe75(%rip),%rax
mov    %rax,-0x128(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x130(%rbp)
lea    0xe72(%rip),%rax
mov    %rax,-0x138(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x118(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x168(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
mov    %rax,%rdi
mov    -0x138(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x120(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
mov    %rax,%rdi
mov    -0x138(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x128(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x158(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
mov    %rax,%rdi
mov    -0x138(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x130(%rbp),%rsi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
mov    %rax,%rdi
mov    -0x138(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcc4(%rip),%rdi
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcd9(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
lea    0xcc4(%rip),%rdi
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
mov    %rax,%rdi
lea    0xcca(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xc38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
xor    %esi,%esi
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xbf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x118(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x118(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
mov    $0x3,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xb32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdx
lea    0xc70(%rip),%rdi
xor    %esi,%esi
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xaeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
mov    $0x100,%ecx
call   1080 <TrimSpace@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xaa4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xa0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xb8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestTrim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1070 <memset@plt>
lea    0xfad(%rip),%rdi
call   1040 <puts@plt>
lea    0xfef(%rip),%rdi
call   1040 <puts@plt>
lea    0xf96(%rip),%rdi
call   1040 <puts@plt>
lea    0xe61(%rip),%r13
lea    0xe2b(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
lea    0xe19(%rip),%rbp
mov    %rax,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
lea    0xf98(%rip),%r12
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xde7(%rip),%r14
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xd82(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xd3b(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
lea    0xd27(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd0c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x64,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xcf2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc45(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xcda(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xcc7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    $0x3,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xcb8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda2(%rip),%rdi
xor    %esi,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xc9c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x64,%esi
mov    %r15,%rdx
mov    $0x100,%ecx
call   10a0 <TrimSpace@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
lea    0xc81(%rip),%rdi
call   1040 <puts@plt>
lea    0xcdd(%rip),%rdi
call   1040 <puts@plt>
lea    0xcd9(%rip),%rdi
call   1040 <puts@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c" This is a test str \00"
@.str.1 = [22 x i8] c" This is a test str\00"
@.str.2 = [22 x i8] c"This is a test str \00"
@.str.3 = [19 x i8] c"This is a test str\00"
@.str.4 = [79 x i8] c"\0A----------------------------------------------------------------------------\0A\00"
@.str.5 = [23 x i8] c" Test trim functions\0A\00"
@.str.6 = [78 x i8] c"----------------------------------------------------------------------------\0A\00"
@.str.7 = [36 x i8] c"Trim start and end spaces of \22%s\22: \00"
@.str.8 = [6 x i8] c"[OK]\0A\00"
@.str.9 = [26 x i8] c" ONELONGSTRINGOFJUNK \00"
@.str.10 = [20 x i8] c"ONELONGSTRINGOFJUNK\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [30 x i8] c"Attempt to trim NULL string: \00"
@.str.13 = [37 x i8] c"Attempt to trim string with 0 size: \00"
@.str.14 = [42 x i8] c"Attempt to trim string with NULL buffer: \00"
@.str.15 = [47 x i8] c"Attempt to trim string with too small buffer: \00"
@.str.16 = [30 x i8] c"Cannot trim an empty string: \00"
@.str.17 = [1 x i8] zeroinitializer
@.str.18 = [28 x i8] c"Cannot trim a NULL string: \00"
@.str.19 = [9 x i8] c" Done.\0A\00"
@.str.20 = [79 x i8] c"----------------------------------------------------------------------------\0A\0A\00"
define void @TestTrim() {
%1 = alloca [257 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 257)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.6, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%18 = call i32* @TrimSpace(i8* %14, i32 %16, i8* %17, i32 256)
%19 = load i8*, i8** %6
%20 = call i64 @strcmp(i32* %18, i8* %19)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%25 = load i8*, i8** %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %3
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%31 = call i32* @TrimSpace(i8* %27, i32 %29, i8* %30, i32 256)
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i32* %31, i8* %32)
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%38 = load i8*, i8** %4
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %4
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%44 = call i32* @TrimSpace(i8* %40, i32 %42, i8* %43, i32 256)
%45 = load i8*, i8** %6
%46 = call i64 @strcmp(i32* %44, i8* %45)
%47 = icmp eq i64 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%51 = load i8*, i8** %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %5
%54 = load i8*, i8** %5
%55 = call i32 @strlen(i8* %54)
%56 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%57 = call i32* @TrimSpace(i8* %53, i32 %55, i8* %56, i32 256)
%58 = load i8*, i8** %6
%59 = call i64 @strcmp(i32* %57, i8* %58)
%60 = icmp eq i64 %59, 0
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%65 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%66 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%67 = call i32* @TrimSpace(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %65, i8* %66, i32 256)
%68 = call i64 @strcmp(i32* %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
%75 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%76 = call i32* @TrimSpace(i8* null, i32 100, i8* %75, i32 256)
%77 = icmp eq i32* %76, null
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
%82 = load i8*, i8** %2
%83 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%84 = call i32* @TrimSpace(i8* %82, i32 0, i8* %83, i32 256)
%85 = icmp eq i32* %84, null
%86 = zext i1 %85 to i32
%87 = call i32 @assert(i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%90 = load i8*, i8** %2
%91 = load i8*, i8** %2
%92 = call i32 @strlen(i8* %91)
%93 = call i32* @TrimSpace(i8* %90, i32 %92, i8* null, i32 256)
%94 = icmp eq i32* %93, null
%95 = zext i1 %94 to i32
%96 = call i32 @assert(i32 %95)
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%99 = load i8*, i8** %2
%100 = load i8*, i8** %2
%101 = call i32 @strlen(i8* %100)
%102 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%103 = call i32* @TrimSpace(i8* %99, i32 %101, i8* %102, i32 3)
%104 = icmp eq i32* %103, null
%105 = zext i1 %104 to i32
%106 = call i32 @assert(i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.16, i64 0, i64 0))
%109 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%110 = call i32* @TrimSpace(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.17, i64 0, i64 0), i32 0, i8* %109, i32 256)
%111 = icmp eq i32* %110, null
%112 = zext i1 %111 to i32
%113 = call i32 @assert(i32 %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0))
%116 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%117 = call i32* @TrimSpace(i8* null, i32 100, i8* %116, i32 256)
%118 = icmp eq i32* %117, null
%119 = zext i1 %118 to i32
%120 = call i32 @assert(i32 %119)
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.6, i64 0, i64 0))
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.20, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c" This is a test str \00"
@.str.1 = [22 x i8] c" This is a test str\00"
@.str.2 = [22 x i8] c"This is a test str \00"
@.str.3 = [19 x i8] c"This is a test str\00"
@.str.7 = [36 x i8] c"Trim start and end spaces of \22%s\22: \00"
@.str.9 = [26 x i8] c" ONELONGSTRINGOFJUNK \00"
@.str.10 = [20 x i8] c"ONELONGSTRINGOFJUNK\00"
@.str.12 = [30 x i8] c"Attempt to trim NULL string: \00"
@.str.13 = [37 x i8] c"Attempt to trim string with 0 size: \00"
@.str.14 = [42 x i8] c"Attempt to trim string with NULL buffer: \00"
@.str.15 = [47 x i8] c"Attempt to trim string with too small buffer: \00"
@.str.16 = [30 x i8] c"Cannot trim an empty string: \00"
@.str.17 = [1 x i8] zeroinitializer
@.str.18 = [28 x i8] c"Cannot trim a NULL string: \00"
@str = [78 x i8] c"\0A----------------------------------------------------------------------------\00"
@str.21 = [22 x i8] c" Test trim functions\00"
@str.33 = [5 x i8] c"[OK]\00"
@str.34 = [77 x i8] c"----------------------------------------------------------------------------\00"
@str.35 = [8 x i8] c" Done.\00"
@str.36 = [78 x i8] c"----------------------------------------------------------------------------\0A\00"
define void @TestTrim() {
%1 = alloca [257 x i8]
%2 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 257)
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.21, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.34, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32* @TrimSpace(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %2, i32 256)
%10 = call i64 @strcmp(i32* %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @TrimSpace(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %2, i32 256)
%18 = call i64 @strcmp(i32* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32* @TrimSpace(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %2, i32 256)
%26 = call i64 @strcmp(i32* %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32* @TrimSpace(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %32, i8* %2, i32 256)
%34 = call i64 @strcmp(i32* %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%41 = call i32* @TrimSpace(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %40, i8* %2, i32 256)
%42 = call i64 @strcmp(i32* %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%47 = call i32 @putchar(i32 10)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
%49 = call i32* @TrimSpace(i8* null, i32 100, i8* %2, i32 256)
%50 = icmp eq i32* %49, null
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
%55 = call i32* @TrimSpace(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i8* %2, i32 256)
%56 = icmp eq i32* %55, null
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%61 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%62 = call i32* @TrimSpace(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %61, i8* null, i32 256)
%63 = icmp eq i32* %62, null
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0))
%68 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%69 = call i32* @TrimSpace(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %68, i8* %2, i32 3)
%70 = icmp eq i32* %69, null
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.16, i64 0, i64 0))
%75 = call i32* @TrimSpace(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.17, i64 0, i64 0), i32 0, i8* %2, i32 256)
%76 = icmp eq i32* %75, null
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0))
%81 = call i32* @TrimSpace(i8* null, i32 100, i8* %2, i32 256)
%82 = icmp eq i32* %81, null
%83 = zext i1 %82 to i32
%84 = call i32 @assert(i32 %83)
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.33, i64 0, i64 0))
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.34, i64 0, i64 0))
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.35, i64 0, i64 0))
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.36, i64 0, i64 0))
ret void
}