#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 strlen(char *);
void edflib_remove_padding_trailing_spaces(char *str) {
  int i;
  while (str[0] == ' ') {
    for (i = 0;; i++) {
      if (str[i] == 0)
        break;
      str[i] = str[i + 1];
    }
  }
  for (i = strlen(str); i > 0; i--) {
    if (str[i - 1] == ' ')
      str[i - 1] = 0;
    else
      break;
  }
}


x86 assembly (clang, -O0):
<edflib_remove_padding_trailing_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    117b <edflib_remove_padding_trailing_spaces+0x6b>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    114d <edflib_remove_padding_trailing_spaces+0x3d>
jmp    1176 <edflib_remove_padding_trailing_spaces+0x66>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <edflib_remove_padding_trailing_spaces+0x23>
jmp    111c <edflib_remove_padding_trailing_spaces+0xc>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11d9 <edflib_remove_padding_trailing_spaces+0xc9>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11c1 <edflib_remove_padding_trailing_spaces+0xb1>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c6 <edflib_remove_padding_trailing_spaces+0xb6>
jmp    11d9 <edflib_remove_padding_trailing_spaces+0xc9>
jmp    11cb <edflib_remove_padding_trailing_spaces+0xbb>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <edflib_remove_padding_trailing_spaces+0x77>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edflib_remove_padding_trailing_spaces>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x20,(%rdi)
jne    1147 <edflib_remove_padding_trailing_spaces+0x37>
xor    %eax,%eax
mov    %rbx,%rcx
xchg   %ax,%ax
movzbl 0x1(%rbx,%rax,1),%edx
mov    %dl,(%rcx)
lea    (%rbx,%rax,1),%rcx
add    $0x1,%rcx
cmpb   $0x0,0x1(%rbx,%rax,1)
lea    0x1(%rax),%rax
jne    1120 <edflib_remove_padding_trailing_spaces+0x10>
cmpb   $0x20,(%rbx)
mov    $0x0,%eax
mov    %rbx,%rcx
je     1120 <edflib_remove_padding_trailing_spaces+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1177 <edflib_remove_padding_trailing_spaces+0x67>
mov    %eax,%eax
add    $0x1,%rax
nopl   0x0(%rax)
lea    -0x2(%rax),%ecx
cmpb   $0x20,(%rbx,%rcx,1)
jne    1177 <edflib_remove_padding_trailing_spaces+0x67>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1160 <edflib_remove_padding_trailing_spaces+0x50>
pop    %rbx
ret

LLVM IR (-O0):
define void @edflib_remove_padding_trailing_spaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %34, %1
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %35
10: ; preds = %4
store i32 0, i32* %3
br label %11
11: ; preds = %31, %10
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11
br label %34
20: ; preds = %11
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %20
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %11
34: ; preds = %19
br label %4
35: ; preds = %4
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %58, %35
%39 = load i32, i32* %3
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %61
41: ; preds = %38
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 32
br i1 %49, label %50, label %56
50: ; preds = %41
%51 = load i8*, i8** %2
%52 = load i32, i32* %3
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 0, i8* %55
br label %57
56: ; preds = %41
br label %61
57: ; preds = %50
br label %58
58: ; preds = %57
%59 = load i32, i32* %3
%60 = add nsw i32 %59, -1
store i32 %60, i32* %3
br label %38
61: ; preds = %56, %38
ret void
}

LLVM IR (-O2):
define void @edflib_remove_padding_trailing_spaces(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 32
br i1 %3, label %7, label %18
4: ; preds = %7
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 32
br i1 %6, label %15, label %18
7: ; preds = %1, %15
%8 = phi i64 [ %16, %15 ], [ 0, %1 ]
%9 = phi i8* [ %17, %15 ], [ %0, %1 ]
%10 = add nuw nsw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
store i8 %12, i8* %9
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 0
br i1 %14, label %4, label %15
15: ; preds = %7, %4
%16 = phi i64 [ %10, %7 ], [ 0, %4 ]
%17 = phi i8* [ %11, %7 ], [ %0, %4 ]
br label %7
18: ; preds = %4, %1
%19 = tail call i32 @strlen(i8* %0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = zext i32 %19 to i64
br label %23
23: ; preds = %21, %30
%24 = phi i64 [ %22, %21 ], [ %25, %30 ]
%25 = add nsw i64 %24, -1
%26 = and i64 %25, 4294967295
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 32
br i1 %29, label %30, label %32
30: ; preds = %23
store i8 0, i8* %27
%31 = icmp ugt i64 %24, 1
br i1 %31, label %23, label %32
32: ; preds = %30, %23, %18
ret void
}