#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 */
char *iso_util_strcopy(char const *, size_t);
char *iso_util_strcopy_untail(const char *buf, size_t len_in) {
  char *str;
  int len;
  str = iso_util_strcopy(buf, len_in);
  if (str == NULL) {
    return NULL;
  }
  for (len = len_in - 1; len >= 0; --len) {
    if (str[len] != ' ')
      break;
    str[len] = 0;
  }
  return str;
}


x86 assembly (clang, -O0):
<iso_util_strcopy_untail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <iso_util_strcopy@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1149 <iso_util_strcopy_untail+0x39>
movq   $0x0,-0x8(%rbp)
jmp    119a <iso_util_strcopy_untail+0x8a>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1192 <iso_util_strcopy_untail+0x82>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1178 <iso_util_strcopy_untail+0x68>
jmp    1192 <iso_util_strcopy_untail+0x82>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <iso_util_strcopy_untail+0x44>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_util_strcopy_untail>:
push   %rbx
mov    %rsi,%rbx
call   1030 <iso_util_strcopy@plt>
test   %rax,%rax
je     1136 <iso_util_strcopy_untail+0x26>
xchg   %ax,%ax
add    $0xffffffff,%ebx
js     1136 <iso_util_strcopy_untail+0x26>
mov    %ebx,%ebx
cmpb   $0x20,(%rax,%rbx,1)
jne    1136 <iso_util_strcopy_untail+0x26>
movb   $0x0,(%rax,%rbx,1)
add    $0xffffffff,%ebx
jns    1125 <iso_util_strcopy_untail+0x15>
pop    %rbx
ret

LLVM IR (-O0):
define i8* @iso_util_strcopy_untail(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = load i64, i64* %5
%10 = call i8* @iso_util_strcopy(i8* %8, i64 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %40
14: ; preds = %2
%15 = load i64, i64* %5
%16 = sub i64 %15, 1
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
br label %18
18: ; preds = %35, %14
%19 = load i32, i32* %7
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %30
29: ; preds = %21
br label %38
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %30
%36 = load i32, i32* %7
%37 = add nsw i32 %36, -1
store i32 %37, i32* %7
br label %18
38: ; preds = %29, %18
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %13
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
define i8* @iso_util_strcopy_untail(i8* %0, i64 %1) {
%3 = tail call i8* @iso_util_strcopy(i8* %0, i64 %1)
%4 = icmp ne i8* %3, null
%5 = trunc i64 %1 to i32
%6 = add i32 %5, -1
%7 = icmp sgt i32 %6, -1
%8 = and i1 %4, %7
br i1 %8, label %9, label %18
9: ; preds = %2, %15
%10 = phi i32 [ %16, %15 ], [ %6, %2 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
br i1 %14, label %15, label %18
15: ; preds = %9
store i8 0, i8* %12
%16 = add i32 %10, -1
%17 = icmp sgt i32 %16, -1
br i1 %17, label %9, label %18
18: ; preds = %9, %15, %2
ret i8* %3
}