#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 */
scalar_t__ isspace(char);
size_t strlen(char *);
void ex_trim_internal(char *name) {
  size_t size;
  char *end;
  if (name == 0)
    return;
  size = strlen(name);
  if (size == 0)
    return;
  end = name + size - 1;
  while (end >= name && isspace(*end))
    end--;
  *(end + 1) = '\0';
}


x86 assembly (clang, -O0):
<ex_trim_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <ex_trim_internal+0x1c>
jmp    11bb <ex_trim_internal+0x9b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1159 <ex_trim_internal+0x39>
jmp    11bb <ex_trim_internal+0x9b>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     1192 <ex_trim_internal+0x72>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a2 <ex_trim_internal+0x82>
jmp    11b3 <ex_trim_internal+0x93>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1169 <ex_trim_internal+0x49>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex_trim_internal>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115d <ex_trim_internal+0x3d>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %rax,%rax
je     115d <ex_trim_internal+0x3d>
lea    (%rax,%r14,1),%rcx
add    $0xffffffffffffffff,%rcx
xchg   %ax,%ax
mov    %rcx,%rbx
cmp    %r14,%rcx
jb     1159 <ex_trim_internal+0x39>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    1140 <ex_trim_internal+0x20>
movb   $0x0,0x1(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @ex_trim_internal(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
br label %36
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %3
%11 = load i64, i64* %3
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
br label %36
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8* %18, i8** %4
br label %19
19: ; preds = %30, %14
%20 = load i8*, i8** %4
%21 = load i8*, i8** %2
%22 = icmp uge i8* %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i64 @isspace(i8 signext %25)
%27 = icmp ne i64 %26, 0
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %4
br label %19
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
br label %36
36: ; preds = %33, %13, %7
ret void
}

LLVM IR (-O2):
define void @ex_trim_internal(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 %4
br label %8
8: ; preds = %12, %6
%9 = phi i8* [ %7, %6 ], [ %10, %12 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = icmp ult i8* %10, %0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i8, i8* %10
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %12
store i8 0, i8* %9
br label %17
17: ; preds = %3, %1, %16
ret void
}