int test_trim(void) {
  char *result;
  const char *test_1 = "\nHello World\n ";
  const char *test_2 = "\n\tWorld\n \t";
  result = trim(test_1);
  do {
    if (!(strcmp(result, "Hello World") == 0)) {
      printf("%sERROR!%s [%s:%d] %s %sFAILED!%s\n", "\x1B[1;31m", "\x1B[1;0m",
             __func__, 146, "strcmp(result, \"Hello World\") == 0",
             "\x1B[1;31m", "\x1B[1;0m");
      return -1;
    }
  } while (0);
  free(result);
  result = trim(test_2);
  do {
    if (!(strcmp(result, "World") == 0)) {
      printf("%sERROR!%s [%s:%d] %s %sFAILED!%s\n", "\x1B[1;31m", "\x1B[1;0m",
             __func__, 150, "strcmp(result, \"World\") == 0", "\x1B[1;31m",
             "\x1B[1;0m");
      return -1;
    }
  } while (0);
  free(result);
  return 0;
}


x86 assembly (clang, -O0):
<test_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <trim@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11d3 <test_trim+0x93>
lea    0xe97(%rip),%rdi
lea    0xeb3(%rip),%r10
lea    0xeb4(%rip),%rax
lea    0xeb4(%rip),%rcx
mov    $0x92,%r8d
lea    0xeb1(%rip),%r9
mov    %r10,%rsi
mov    %rax,%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <test_trim+0x12b>
jmp    11d8 <test_trim+0x98>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1050 <trim@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1256 <test_trim+0x116>
lea    0xe14(%rip),%rdi
lea    0xe30(%rip),%r10
lea    0xe31(%rip),%rax
lea    0xe31(%rip),%rcx
mov    $0x96,%r8d
lea    0xe51(%rip),%r9
mov    %r10,%rsi
mov    %rax,%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <test_trim+0x12b>
jmp    125b <test_trim+0x11b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trim>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1050 <trim@plt>
movslq %eax,%rbx
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1193 <test_trim+0x53>
lea    0xee2(%rip),%rdx
lea    0xed3(%rip),%rsi
lea    0xea9(%rip),%rdi
lea    0xed4(%rip),%rcx
lea    0xed7(%rip),%r9
mov    $0x92,%r8d
jmp    11ea <test_trim+0xaa>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe6d(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <trim@plt>
movslq %eax,%r14
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1206 <test_trim+0xc6>
lea    0xe89(%rip),%rdx
lea    0xe7a(%rip),%rsi
lea    0xe50(%rip),%rdi
lea    0xe7b(%rip),%rcx
lea    0xea1(%rip),%r9
mov    $0x96,%r8d
xor    %eax,%eax
push   %rdx
push   %rsi
call   1040 <printf@plt>
add    $0x10,%rsp
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11fc <test_trim+0xbc>

LLVM IR (-O0):
@.str = [15 x i8] c"\0AHello World\0A \00"
@.str.1 = [11 x i8] c"\0A\09World\0A \09\00"
@.str.2 = [12 x i8] c"Hello World\00"
@.str.3 = [35 x i8] c"%sERROR!%s [%s:%d] %s %sFAILED!%s\0A\00"
@.str.4 = [8 x i8] c"\1B[1;31m\00"
@.str.5 = [7 x i8] c"\1B[1;0m\00"
@__func__.test_trim = [10 x i8] c"test_trim\00"
@.str.6 = [35 x i8] c"strcmp(result, \22Hello World\22) == 0\00"
@.str.7 = [6 x i8] c"World\00"
@.str.8 = [29 x i8] c"strcmp(result, \22World\22) == 0\00"
define i32 @test_trim() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %3
%6 = call i32 (i8*, ...) bitcast (i32 (...)* @trim to i32 (i8*, ...)*)(i8* %5)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
br label %9
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_trim, i64 0, i64 0), i32 146, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
15: ; preds = %9
br label %16
16: ; preds = %15
%17 = load i8*, i8** %2
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @trim to i32 (i8*, ...)*)(i8* %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %2
br label %22
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_trim, i64 0, i64 0), i32 150, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = load i8*, i8** %2
store i32 0, i32* %1
br label %31
31: ; preds = %29, %26, %13
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [15 x i8] c"\0AHello World\0A \00"
@.str.1 = [11 x i8] c"\0A\09World\0A \09\00"
@.str.2 = [12 x i8] c"Hello World\00"
@.str.3 = [35 x i8] c"%sERROR!%s [%s:%d] %s %sFAILED!%s\0A\00"
@.str.4 = [8 x i8] c"\1B[1;31m\00"
@.str.5 = [7 x i8] c"\1B[1;0m\00"
@__func__.test_trim = [10 x i8] c"test_trim\00"
@.str.6 = [35 x i8] c"strcmp(result, \22Hello World\22) == 0\00"
@.str.7 = [6 x i8] c"World\00"
@.str.8 = [29 x i8] c"strcmp(result, \22World\22) == 0\00"
define i32 @test_trim() {
%1 = tail call i32 (i8*, ...) bitcast (i32 (...)* @trim to i32 (i8*, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = sext i32 %1 to i64
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_trim, i64 0, i64 0), i32 146, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %17
8: ; preds = %0
tail call void @free(i8* %3)
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @trim to i32 (i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.test_trim, i64 0, i64 0), i32 150, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %17
16: ; preds = %8
tail call void @free(i8* %11)
br label %17
17: ; preds = %16, %14, %6
%18 = phi i32 [ 0, %16 ], [ -1, %14 ], [ -1, %6 ]
ret i32 %18
}