#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_log(int, int, char *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
char *trim_str(char *);
int test_trim_str(int verbose) {
  int ok = 1;
  char *tmp = " a \t";
  char *res = trim_str(tmp);
  assert_log(!strcmp("a", res), verbose, "trim 1 !ok", &ok);
  tmp = "ab \t\n";
  res = trim_str(tmp);
  assert_log(!strcmp("ab", res), verbose, "trim 2 !ok", &ok);
  tmp = "\t \r   \t \t\n";
  res = trim_str(tmp);
  assert_log(!strcmp("", res), verbose, "trim 3 !ok", &ok);
  return ok;
}


x86 assembly (clang, -O0):
<test_trim_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <trim_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe86(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <trim_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe52(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
lea    0xe4d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <trim_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe20(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trim_str>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x1,0x4(%rsp)
lea    0xebb(%rip),%rdi
call   1030 <trim_str@plt>
lea    0xeb4(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe9f(%rip),%rdx
lea    0x4(%rsp),%r14
mov    %ebx,%esi
mov    %r14,%rcx
call   1050 <assert_log@plt>
lea    0xe94(%rip),%rdi
call   1030 <trim_str@plt>
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe7a(%rip),%rdx
mov    %ebx,%esi
mov    %r14,%rcx
call   1050 <assert_log@plt>
lea    0xe74(%rip),%rdi
call   1030 <trim_str@plt>
xor    %edi,%edi
cmpb   $0x0,(%rax)
sete   %dil
lea    0xe6a(%rip),%rdx
mov    %ebx,%esi
mov    %r14,%rcx
call   1050 <assert_log@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c" a \09\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"trim 1 !ok\00"
@.str.3 = [6 x i8] c"ab \09\0A\00"
@.str.4 = [3 x i8] c"ab\00"
@.str.5 = [11 x i8] c"trim 2 !ok\00"
@.str.6 = [11 x i8] c"\09 \0D \09 \09\0A\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [11 x i8] c"trim 3 !ok\00"
define i32 @test_trim_str(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %2
store i32 1, i32* %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @trim_str(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = load i32, i32* %2
%14 = call i32 @assert_log(i32 %12, i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %4
%15 = load i8*, i8** %4
%16 = call i8* @trim_str(i8* %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
%22 = load i32, i32* %2
%23 = call i32 @assert_log(i32 %21, i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %3)
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %4
%24 = load i8*, i8** %4
%25 = call i8* @trim_str(i8* %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i32 @strcmp(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
%30 = zext i1 %29 to i32
%31 = load i32, i32* %2
%32 = call i32 @assert_log(i32 %30, i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c" a \09\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"trim 1 !ok\00"
@.str.3 = [6 x i8] c"ab \09\0A\00"
@.str.4 = [3 x i8] c"ab\00"
@.str.5 = [11 x i8] c"trim 2 !ok\00"
@.str.6 = [11 x i8] c"\09 \0D \09 \09\0A\00"
@.str.8 = [11 x i8] c"trim 3 !ok\00"
define i32 @test_trim_str(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = tail call i8* @trim_str(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcmp(i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %4)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert_log(i32 %7, i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = call i8* @trim_str(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* dereferenceable(1) %9)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert_log(i32 %12, i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%14 = call i8* @trim_str(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert_log(i32 %17, i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
ret i32 %19
}