#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 *);
int /*<<< orphan*/ system(char *);
int trim(char *, char *);
int /*<<< orphan*/ trimSample();
int main(void) {
  trimSample();
  char *p = "      abcddsgadsgefg      ";
  int ret = 0;
  char buf[100] = {0};
  ret = trim(p, buf);
  if (ret != 0) {
    return ret;
  }
  printf("buf = %s\n", buf);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <trimSample@plt>
lea    0xe90(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <trim@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b0 <main+0x60>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <main+0x83>
lea    -0x80(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1030 <trimSample@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe85(%rip),%rdi
mov    %rsp,%rsi
call   1060 <trim@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11a4 <main+0x64>
lea    0xe8b(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
call   1040 <system@plt>
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c" abcddsgadsgefg \00"
@.str.1 = [10 x i8] c"buf = %s\0A\00"
@.str.2 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i32 (...) @trimSample()
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 0, i32* %3
%6 = bitcast [100 x i8]* %4 to i8*
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32 @trim(i8* %7, i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i32, i32* %3
store i32 %13, i32* %1
br label %18
14: ; preds = %0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %18
18: ; preds = %14, %12
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [27 x i8] c" abcddsgadsgefg \00"
@.str.1 = [10 x i8] c"buf = %s\0A\00"
@.str.2 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i32 (...) @trimSample()
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32 @trim(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %0, %6
ret i32 %4
}