#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);
char *str_strip(char *str) {
  char *ptr = str;
  while (*ptr != 0)
    ptr++;
  --ptr;
  while ((isspace(*ptr))) {
    *ptr = 0;
    ptr--;
  }
  return str;
}


x86 assembly (clang, -O0):
<str_strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1145 <str_strip+0x35>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <str_strip+0x14>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     117f <str_strip+0x6f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1151 <str_strip+0x41>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_strip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rbx)
lea    0x1(%rbx),%rbx
jne    1120 <str_strip+0x10>
movsbl (%rbx),%edi
nopl   (%rax)
call   1030 <isspace@plt>
test   %rax,%rax
je     1147 <str_strip+0x37>
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
jmp    1130 <str_strip+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_strip(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %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 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %3
br label %16
16: ; preds = %21, %13
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8*, i8** %3
store i8 0, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %3
br label %16
25: ; preds = %16
%26 = load i8*, i8** %2
ret i8* %26
}

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