#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);
int strlen(char *);
*MAG_Trim(char *str) {
  char *end;
  while (isspace(*str))
    str++;
  if (*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while (end > str && isspace(*end))
    end--;
  *(end + 1) = 0;
  return str;
}


x86 assembly (clang, -O0):
<MAG_Trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1153 <MAG_Trim+0x33>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <MAG_Trim+0xc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1170 <MAG_Trim+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <MAG_Trim+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    11be <MAG_Trim+0x9e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ce <MAG_Trim+0xae>
jmp    11df <MAG_Trim+0xbf>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1195 <MAG_Trim+0x75>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAG_Trim>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nop
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1130 <MAG_Trim+0x10>
cmpb   $0x0,(%rbx)
je     1185 <MAG_Trim+0x65>
lea    -0x1(%rbx),%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%r15
lea    (%r12,%r14,1),%rax
cmp    %rbx,%rax
jbe    117f <MAG_Trim+0x5f>
movsbl (%r15,%r14,1),%edi
call   1040 <isspace@plt>
lea    -0x1(%r15),%r12
test   %rax,%rax
jne    1160 <MAG_Trim+0x40>
movb   $0x0,0x1(%r15,%r14,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @MAG_Trim(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = call i64 @isspace(i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %5
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = bitcast i8* %19 to i32*
store i32* %20, i32** %2
br label %47
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -1
store i8* %27, i8** %4
br label %28
28: ; preds = %39, %21
%29 = load i8*, i8** %4
%30 = load i8*, i8** %3
%31 = icmp ugt i8* %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = call i64 @isspace(i8 signext %34)
%36 = icmp ne i64 %35, 0
br label %37
37: ; preds = %32, %28
%38 = phi i1 [ false, %28 ], [ %36, %32 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 -1
store i8* %41, i8** %4
br label %28
42: ; preds = %37
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8 0, i8* %44
%45 = load i8*, i8** %3
%46 = bitcast i8* %45 to i32*
store i32* %46, i32** %2
br label %47
47: ; preds = %42, %18
%48 = load i32*, i32** %2
ret i32* %48
}

LLVM IR (-O2):
define i32* @MAG_Trim(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 signext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %3)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %3, i64 %13
br label %15
15: ; preds = %19, %11
%16 = phi i8* [ %14, %11 ], [ %17, %19 ]
%17 = getelementptr inbounds i8, i8* %16, i64 -1
%18 = icmp ugt i8* %17, %3
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8, i8* %17
%21 = tail call i64 @isspace(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %19
store i8 0, i8* %16
br label %24
24: ; preds = %8, %23
%25 = bitcast i8* %3 to i32*
ret i32* %25
}