#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(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ trim(char *);
int test_trim() {
  char str[20];
  printf("test_trim...");
  sprintf(str, "%s", "  test string   ");
  trim(str);
  assert(str[0] == 't');
  assert(str[strlen(str) - 1] == 'g');
  printf("ok\n");
  return 1;
}


x86 assembly (clang, -O0):
<test_trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xe9e(%rip),%rsi
lea    0xe9a(%rip),%rdx
call   1070 <sprintf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <trim@plt>
movsbl -0x20(%rbp),%eax
cmp    $0x74,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x67,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_trim>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
movups 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <trim@plt>
xor    %edi,%edi
cmpb   $0x74,(%rsp)
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %edi,%edi
cmpb   $0x67,-0x1(%rax,%rbx,1)
sete   %dil
call   1070 <assert@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"test_trim...\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c" test string \00"
@.str.3 = [4 x i8] c"ok\0A\00"
define i32 @test_trim() {
%1 = alloca [20 x i8]
%2 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%6 = call i32 @trim(i8* %5)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 116
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 103
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [13 x i8] c"test_trim...\00"
@.str.2 = [17 x i8] c" test string \00"
@str = [3 x i8] c"ok\00"
define i32 @test_trim() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @trim(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 116
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i32 @strlen(i8* %2)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 103
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret i32 1
}