#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 trim_trailing_zeros(char *str) {
  char *ptr, *totrim = NULL;
  int len;
  int i;
  ((void)0);
  ptr = strchr(str, '.');
  if (!ptr)
    return;
  ((void)0);
  len = strlen(ptr);
  for (i = len - 1; i; i--) {
    if (ptr[i] != '0')
      break;
    totrim = &ptr[i];
  }
  if (totrim) {
    if (ptr == totrim - 1)
      *ptr = '\0';
    else
      *totrim = '\0';
  }
  ((void)0);
}


x86 assembly (clang, -O0):
<trim_trailing_zeros>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <trim_trailing_zeros+0x36>
jmp    11e4 <trim_trailing_zeros+0xc4>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11ac <trim_trailing_zeros+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     118f <trim_trailing_zeros+0x6f>
jmp    11ac <trim_trailing_zeros+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    116b <trim_trailing_zeros+0x4b>
cmpq   $0x0,-0x18(%rbp)
je     11e4 <trim_trailing_zeros+0xc4>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11d8 <trim_trailing_zeros+0xb8>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11df <trim_trailing_zeros+0xbf>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e4 <trim_trailing_zeros+0xc4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailing_zeros>:
push   %rbx
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1195 <trim_trailing_zeros+0x75>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
je     1195 <trim_trailing_zeros+0x75>
movslq %ecx,%rcx
cmpb   $0x30,(%rbx,%rcx,1)
jne    1180 <trim_trailing_zeros+0x60>
add    %rbx,%rcx
add    $0xfffffffe,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
sub    $0x1,%eax
jb     1187 <trim_trailing_zeros+0x67>
lea    -0x1(%rcx),%rdx
cmpb   $0x30,-0x1(%rcx)
mov    %rdx,%rcx
je     1160 <trim_trailing_zeros+0x40>
add    $0x1,%rdx
mov    %rdx,%rcx
test   %rcx,%rcx
jne    1187 <trim_trailing_zeros+0x67>
jmp    1195 <trim_trailing_zeros+0x75>
xor    %ecx,%ecx
test   %rcx,%rcx
je     1195 <trim_trailing_zeros+0x75>
lea    -0x1(%rcx),%rax
cmp    %rax,%rbx
cmove  %rbx,%rcx
movb   $0x0,(%rcx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @trim_trailing_zeros(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %31, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %2)
%6 = add i32 %5, -1
%7 = icmp eq i32 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %4
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 48
br i1 %12, label %13, label %23
13: ; preds = %8, %19
%14 = phi i8* [ %20, %19 ], [ %10, %8 ]
%15 = phi i64 [ %16, %19 ], [ %9, %8 ]
%16 = add nsw i64 %15, -1
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %2, i64 %16
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 48
br i1 %22, label %13, label %23
23: ; preds = %19, %8
%24 = phi i8* [ null, %8 ], [ %14, %19 ]
%25 = icmp eq i8* %24, null
br i1 %25, label %31, label %26
26: ; preds = %13, %23
%27 = phi i8* [ %24, %23 ], [ %14, %13 ]
%28 = getelementptr inbounds i8, i8* %27, i64 -1
%29 = icmp eq i8* %2, %28
%30 = select i1 %29, i8* %2, i8* %27
store i8 0, i8* %30
br label %31
31: ; preds = %26, %4, %23, %1
ret void
}