#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*/ printf(char *, char *, char *);
char *str_trim(char *);
void test_str_trim() {
  char *data[16] = {
      "  simple text  ",
      "  simple text",
      "simple text",
      " text ",
      " ",
      "",
      "\n\t\v",
      "",
      " simple text",
      "Remember good   ",
      "    By center   ",
      " \t\n\r\b\a\v By center \t\n\r\b\a\v ",
      "    ",
      "\t\n\r\b\a\v",
      " \t\n\r\b\a\v simple text ",
      "Remember good  \t\n\r\b\a\v ",
  };
  for (int i = 0; i < 10; ++i) {
    printf("\"%s\" --> \"%s\"\n", data[i], str_trim(data[i]));
  }
}


x86 assembly (clang, -O0):
<test_str_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x80(%rbp),%rdi
lea    0x2c5a(%rip),%rsi
mov    $0x80,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0xa,-0x84(%rbp)
jge    11b5 <test_str_trim+0x85>
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rax
mov    %rax,-0x90(%rbp)
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
call   1050 <str_trim@plt>
mov    -0x90(%rbp),%rsi
mov    %rax,%rdx
lea    0xefa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    115a <test_str_trim+0x2a>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_trim>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
lea    0xeff(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xec0(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xea5(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xe94(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xe91(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xe84(%rip),%r15
mov    %r15,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xe44(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    %r15,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xdfd(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xdf8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <str_trim@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c" simple text \00"
@.str.1 = [14 x i8] c" simple text\00"
@.str.2 = [12 x i8] c"simple text\00"
@.str.3 = [7 x i8] c" text \00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [4 x i8] c"\0A\09\0B\00"
@.str.7 = [13 x i8] c" simple text\00"
@.str.8 = [17 x i8] c"Remember good \00"
@.str.9 = [17 x i8] c" By center \00"
@.str.10 = [26 x i8] c" \09\0A\0D\08\07\0B By center \09\0A\0D\08\07\0B \00"
@.str.11 = [5 x i8] c" \00"
@.str.12 = [7 x i8] c"\09\0A\0D\08\07\0B\00"
@.str.13 = [21 x i8] c" \09\0A\0D\08\07\0B simple text \00"
@.str.14 = [23 x i8] c"Remember good \09\0A\0D\08\07\0B \00"
@__const.test_str_trim.data = [16 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i32 0, i32 0)]
@.str.15 = [15 x i8] c"\22%s\22 --> \22%s\22\0A\00"
define void @test_str_trim() {
%1 = alloca [16 x i8*]
%2 = alloca i32
%3 = bitcast [16 x i8*]* %1 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [16 x i8*], [16 x i8*]* %1, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [16 x i8*], [16 x i8*]* %1, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = call i8* @str_trim(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* %11, i8* %16)
br label %18
18: ; preds = %7
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %4
21: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c" simple text \00"
@.str.1 = [14 x i8] c" simple text\00"
@.str.2 = [12 x i8] c"simple text\00"
@.str.3 = [7 x i8] c" text \00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [4 x i8] c"\0A\09\0B\00"
@.str.7 = [13 x i8] c" simple text\00"
@.str.8 = [17 x i8] c"Remember good \00"
@.str.15 = [15 x i8] c"\22%s\22 --> \22%s\22\0A\00"
define void @test_str_trim() {
%1 = tail call i8* @str_trim(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i8* @str_trim(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = tail call i8* @str_trim(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = tail call i8* @str_trim(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i8* @str_trim(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = tail call i8* @str_trim(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%13 = tail call i8* @str_trim(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%15 = tail call i8* @str_trim(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = tail call i8* @str_trim(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %17)
%19 = tail call i8* @str_trim(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %19)
ret void
}