#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 versnorm(char *vers) {
  char *pe = vers + strlen(vers) - 1;
  while (pe > vers) {
    if (*pe == '.') {
      *pe = '\0';
      pe--;
    } else if (*pe == '0') {
      pe--;
    } else {
      break;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<versnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11a7 <versnorm+0x97>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1177 <versnorm+0x67>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11a2 <versnorm+0x92>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1198 <versnorm+0x88>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    119d <versnorm+0x8d>
jmp    11a7 <versnorm+0x97>
jmp    11a2 <versnorm+0x92>
jmp    1141 <versnorm+0x31>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<versnorm>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    1134 <versnorm+0x24>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    114b <versnorm+0x3b>
movzbl (%rax),%ecx
cmp    $0x30,%cl
je     1130 <versnorm+0x20>
cmp    $0x2e,%cl
jne    114b <versnorm+0x3b>
movb   $0x0,(%rax)
jmp    1130 <versnorm+0x20>
pop    %rbx
ret

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

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