#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 *);
char *get_str_without_after_space(char *target) {
  char *pos;
  if (!target) {
    return NULL;
  }
  pos = target + strlen(target) - 1;
  for (; pos > target; pos--) {
    if (*pos != ' ')
      break;
    *pos = '\0';
  }
  return target;
}


x86 assembly (clang, -O0):
<get_str_without_after_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <get_str_without_after_space+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119c <get_str_without_after_space+0x8c>
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),%rax
cmp    -0x10(%rbp),%rax
jbe    1194 <get_str_without_after_space+0x84>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     117c <get_str_without_after_space+0x6c>
jmp    1194 <get_str_without_after_space+0x84>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1159 <get_str_without_after_space+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_str_without_after_space>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1141 <get_str_without_after_space+0x31>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    1141 <get_str_without_after_space+0x31>
nop
cmpb   $0x20,(%rax)
jne    1141 <get_str_without_after_space+0x31>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
ja     1130 <get_str_without_after_space+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

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