#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 *, ...);
char *strdup(char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, scalar_t__);
int /*<<< orphan*/ trim(char *);
int test_trim(char *in, char *out) {
  char *test;
  printf("   trim( '%s', '%s') ", in, out);
  test = strdup(in);
  if (test != NULL) {
    trim(test);
    printf(" = '%s' ", test);
    if (strlen(test) == strlen(out)) {
      if (strncmp(test, out, strlen(out)) == 0) {
        printf("passed\n");
        free(test);
        return (0);
      }
    }
    free(test);
  }
  printf("failed\n");
  return (1);
}


x86 assembly (clang, -O0):
<test_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1243 <test_trim+0xe3>
mov    -0x20(%rbp),%rdi
call   1070 <trim@plt>
mov    -0x20(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    123a <test_trim+0xda>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1235 <test_trim+0xd5>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1258 <test_trim+0xf8>
jmp    123a <test_trim+0xda>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trim>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
je     11eb <test_trim+0x7b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <trim@plt>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <strlen@plt>
cmp    %rax,%r15
jne    11e3 <test_trim+0x73>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1202 <test_trim+0x92>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe2d(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe1d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11fc <test_trim+0x8c>

LLVM IR (-O0):
@.str = [22 x i8] c" trim( '%s', '%s') \00"
@.str.1 = [9 x i8] c" = '%s' \00"
@.str.2 = [8 x i8] c"passed\0A\00"
@.str.3 = [8 x i8] c"failed\0A\00"
define i32 @test_trim(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %39
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @trim(i8* %15)
%17 = load i8*, i8** %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %6
%20 = call i64 @strlen(i8* %19)
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = icmp eq i64 %20, %22
br i1 %23, label %24, label %36
24: ; preds = %14
%25 = load i8*, i8** %6
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i64 @strlen(i8* %27)
%29 = call i64 @strncmp(i8* %25, i8* %26, i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
store i32 0, i32* %3
br label %41
35: ; preds = %24
br label %36
36: ; preds = %35, %14
%37 = load i8*, i8** %6
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %36, %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %41
41: ; preds = %39, %31
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [22 x i8] c" trim( '%s', '%s') \00"
@.str.1 = [9 x i8] c" = '%s' \00"
@str = [7 x i8] c"failed\00"
@str.4 = [7 x i8] c"passed\00"
define i32 @test_trim(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @trim(i8* %4)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = tail call i64 @strlen(i8* %4)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = tail call i64 @strncmp(i8* %4, i8* %1, i64 %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0))
%17 = tail call i32 @free(i8* %4)
br label %22
18: ; preds = %12, %6
%19 = tail call i32 @free(i8* %4)
br label %20
20: ; preds = %18, %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = phi i32 [ 0, %15 ], [ 1, %20 ]
ret i32 %23
}