#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*/ strncpy(char *, char const *, int const);
void dumpio_trim_str(char *_str, const char *str, const int str_len) {
  int i;
  strncpy(_str, str, str_len);
  _str[str_len] = ' ';
  for (i = str_len - 1; i >= 0; i--) {
    if (_str[i] == '\0') {
      _str[i] = ' ';
    } else {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<dumpio_trim_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1190 <dumpio_trim_str+0x80>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1178 <dumpio_trim_str+0x68>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    117d <dumpio_trim_str+0x6d>
jmp    1190 <dumpio_trim_str+0x80>
jmp    1182 <dumpio_trim_str+0x72>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1148 <dumpio_trim_str+0x38>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpio_trim_str>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x20,(%rbx,%rax,1)
test   %eax,%eax
jle    1147 <dumpio_trim_str+0x37>
mov    %ebp,%eax
add    $0x1,%rax
xchg   %ax,%ax
lea    -0x2(%rax),%ecx
cmpb   $0x0,(%rbx,%rcx,1)
jne    1147 <dumpio_trim_str+0x37>
movb   $0x20,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1130 <dumpio_trim_str+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @dumpio_trim_str(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @strncpy(i8* %8, i8* %9, i32 %10)
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 32, i8* %15
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %7
br label %18
18: ; preds = %36, %3
%19 = load i32, i32* %7
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load i8*, i8** %4
%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 eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 32, i8* %33
br label %35
34: ; preds = %21
br label %39
35: ; preds = %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, -1
store i32 %38, i32* %7
br label %18
39: ; preds = %34, %18
ret void
}

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