#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*/ free(char *);
int /*<<< orphan*/ printf(char *, int, char const *);
char *str_trim(char *);
scalar_t__ strcmp(char *, char const *);
char *strdup(char *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ test_result(char *, int);
void test_trim(void) {
  bool pass;
  const char *ref = "test string";
  char *check;
  char *teststr = strdup("\n\t test string \t  \n");
  check = str_trim(teststr);
  pass = strcmp(check, ref) == 0;
  test_result("str_trim", pass);
  if (!pass) {
    printf("(%d) %s\n", (int)strlen(check), check);
    printf("(%d) %s\n", (int)strlen(ref), ref);
  }
  free(teststr);
}


x86 assembly (clang, -O0):
<test_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe82(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <str_trim@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe5a(%rip),%rdi
call   1030 <test_result@plt>
cmpl   $0x0,-0x4(%rbp)
jne    120b <test_trim+0x9b>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe3e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xe23(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trim>:
push   %r15
push   %r14
push   %rbx
lea    0xe90(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <str_trim@plt>
mov    %rax,%r15
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
mov    %rax,%rbx
xor    %esi,%esi
test   %rax,%rax
sete   %sil
lea    0xe6f(%rip),%rdi
call   1030 <test_result@plt>
test   %rbx,%rbx
je     11eb <test_trim+0x7b>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0xe5f(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1060 <printf@plt>
lea    0xe22(%rip),%rdx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"test string\00"
@.str.1 = [20 x i8] c"\0A\09 test string \09 \0A\00"
@.str.2 = [9 x i8] c"str_trim\00"
@.str.3 = [9 x i8] c"(%d) %s\0A\00"
define void @test_trim() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = call i8* @strdup(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @str_trim(i8* %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i8*, i8** %2
%10 = call i64 @strcmp(i8* %8, i8* %9)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = call i32 @test_result(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %1
%16 = icmp ne i32 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %0
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
%20 = trunc i64 %19 to i32
%21 = load i8*, i8** %3
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %20, i8* %21)
%23 = load i8*, i8** %2
%24 = call i64 @strlen(i8* %23)
%25 = trunc i64 %24 to i32
%26 = load i8*, i8** %2
%27 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %26)
br label %28
28: ; preds = %17, %0
%29 = load i8*, i8** %4
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"test string\00"
@.str.1 = [20 x i8] c"\0A\09 test string \09 \0A\00"
@.str.2 = [9 x i8] c"str_trim\00"
@.str.3 = [9 x i8] c"(%d) %s\0A\00"
define void @test_trim() {
%1 = tail call dereferenceable_or_null(20) i8* @strdup(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i8* @str_trim(i8* %1)
%3 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @test_result(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br i1 %4, label %12, label %7
7: ; preds = %0
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = trunc i64 %8 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* %2)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %7, %0
%13 = tail call i32 @free(i8* %1)
ret void
}