#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_string(char *);
char *str_dup(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *string_unpad(char *argument) {
  char buf[8192];
  char *s;
  s = argument;
  while (*s == ' ')
    s++;
  strcpy(buf, s);
  s = buf;
  if (*s != '\0') {
    while (*s != '\0')
      s++;
    s--;
    while (*s == ' ')
      s--;
    s++;
    *s = '\0';
  }
  free_string(argument);
  return str_dup(buf);
}


x86 assembly (clang, -O0):
<string_unpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1174 <string_unpad+0x44>
mov    -0x2018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2018(%rbp)
jmp    114a <string_unpad+0x1a>
lea    -0x2010(%rbp),%rdi
mov    -0x2018(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122f <string_unpad+0xff>
jmp    11ad <string_unpad+0x7d>
mov    -0x2018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <string_unpad+0xa7>
mov    -0x2018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2018(%rbp)
jmp    11ad <string_unpad+0x7d>
mov    -0x2018(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1213 <string_unpad+0xe3>
mov    -0x2018(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x2018(%rbp)
jmp    11e9 <string_unpad+0xb9>
mov    -0x2018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <free_string@plt>
lea    -0x2010(%rbp),%rdi
call   1050 <str_dup@plt>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_unpad>:
push   %rbx
sub    $0x2000,%rsp
mov    %rdi,%rbx
lea    -0x1(%rdi),%rsi
nop
cmpb   $0x20,0x1(%rsi)
lea    0x1(%rsi),%rsi
je     1140 <string_unpad+0x10>
mov    %rsp,%rdi
call   1030 <strcpy@plt>
cmpb   $0x0,(%rsp)
je     117d <string_unpad+0x4d>
lea    0x1(%rsp),%rax
nopl   (%rax)
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1160 <string_unpad+0x30>
nopl   0x0(%rax)
cmpb   $0x20,-0x2(%rax)
lea    -0x1(%rax),%rax
je     1170 <string_unpad+0x40>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <free_string@plt>
mov    %rsp,%rdi
call   1050 <str_dup@plt>
add    $0x2000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @string_unpad(i8* %0) {
%2 = alloca [8192 x i8]
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %8, %4 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = call i32 @strcpy(i8* %3, i8* %5)
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %9, %13
%14 = phi i8* [ %15, %13 ], [ %3, %9 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %13
18: ; preds = %13, %18
%19 = phi i8* [ %20, %18 ], [ %15, %13 ]
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
br i1 %22, label %18, label %23
23: ; preds = %18
store i8 0, i8* %19
br label %24
24: ; preds = %23, %9
%25 = call i32 @free_string(i8* %0)
%26 = call i8* @str_dup(i8* %3)
ret i8* %26
}