#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 convert_trailing_zeros_to_spaces(char *str) {
  int i, j, len;
  len = strlen(str);
  for (i = 0; i < len; i++) {
    if (str[i] == '.') {
      for (j = (len - 1); j >= 0; j--) {
        if ((str[j] != '.') && (str[j] != '0')) {
          break;
        }
        if (str[j] == '.') {
          str[j] = ' ';
          break;
        }
        str[j] = ' ';
      }
      break;
    }
  }
}


x86 assembly (clang, -O0):
<convert_trailing_zeros_to_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <convert_trailing_zeros_to_spaces+0xda>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11d7 <convert_trailing_zeros_to_spaces+0xc7>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11d2 <convert_trailing_zeros_to_spaces+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1192 <convert_trailing_zeros_to_spaces+0x82>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     1192 <convert_trailing_zeros_to_spaces+0x82>
jmp    11d2 <convert_trailing_zeros_to_spaces+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11b8 <convert_trailing_zeros_to_spaces+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    11d2 <convert_trailing_zeros_to_spaces+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1159 <convert_trailing_zeros_to_spaces+0x49>
jmp    11ea <convert_trailing_zeros_to_spaces+0xda>
jmp    11dc <convert_trailing_zeros_to_spaces+0xcc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112f <convert_trailing_zeros_to_spaces+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_trailing_zeros_to_spaces>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    113f <convert_trailing_zeros_to_spaces+0x2f>
mov    %eax,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x2e,(%rbx,%rcx,1)
je     1141 <convert_trailing_zeros_to_spaces+0x31>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1130 <convert_trailing_zeros_to_spaces+0x20>
pop    %rbx
ret
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x2(%rax),%ecx
movzbl (%rbx,%rcx,1),%edx
cmp    $0x30,%dl
jne    116c <convert_trailing_zeros_to_spaces+0x5c>
movb   $0x20,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jg     1150 <convert_trailing_zeros_to_spaces+0x40>
jmp    113f <convert_trailing_zeros_to_spaces+0x2f>
cmp    $0x2e,%dl
jne    113f <convert_trailing_zeros_to_spaces+0x2f>
movb   $0x20,(%rbx,%rcx,1)
pop    %rbx
ret

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

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