#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 *strchr(char *, char);
int strlen(char *);
void backward_zero_eater(char *str) {
  str = strchr(str, '.');
  if (str == NULL)
    return;
  str++;
  size_t fraction = strlen(str) - 1;
  while (true) {
    if (str[fraction] == '0')
      str[fraction] = '\0';
    else
      break;
    fraction--;
  }
  if (str[fraction] == '.')
    str[fraction] = '\0';
}


x86 assembly (clang, -O0):
<backward_zero_eater>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114e <backward_zero_eater+0x2e>
jmp    11c9 <backward_zero_eater+0xa9>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    1192 <backward_zero_eater+0x72>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1197 <backward_zero_eater+0x77>
jmp    11a8 <backward_zero_eater+0x88>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    116c <backward_zero_eater+0x4c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11c9 <backward_zero_eater+0xa9>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backward_zero_eater>:
push   %rbx
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1169 <backward_zero_eater+0x49>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
cmp    $0x30,%cl
jne    1161 <backward_zero_eater+0x41>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
jmp    1150 <backward_zero_eater+0x30>
cmp    $0x2e,%cl
jne    1169 <backward_zero_eater+0x49>
movb   $0x0,(%rax)
pop    %rbx
ret

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

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