#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 *);
char *numstr_round_repeating(char *num) {
  char *p = strchr(num, '.');
  if (!p)
    return num;
  for (int i = 1; i < strlen(p) - 1; i++)
    if (p[i] == p[i + 1])
      if (p[i] == '0')
        p[i] = '\0';
      else {
        p[i + 1] = '~';
        p[i + 2] = '\0';
      }
  return num;
}


x86 assembly (clang, -O0):
<numstr_round_repeating>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <numstr_round_repeating+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1209 <numstr_round_repeating+0xe9>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1201 <numstr_round_repeating+0xe1>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11ee <numstr_round_repeating+0xce>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    11c7 <numstr_round_repeating+0xa7>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e9 <numstr_round_repeating+0xc9>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x7e,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ee <numstr_round_repeating+0xce>
jmp    11f3 <numstr_round_repeating+0xd3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <numstr_round_repeating+0x3d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numstr_round_repeating>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119b <numstr_round_repeating+0x7b>
mov    %rax,%r15
mov    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     119b <numstr_round_repeating+0x7b>
lea    0x3(%r15),%rbx
mov    $0x1,%eax
jmp    1184 <numstr_round_repeating+0x64>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x7e,-0x1(%rbx)
mov    %rbx,%rax
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
movslq %eax,%rcx
add    $0x1,%rbx
mov    %r12,%rax
cmp    %rcx,%r12
jge    119b <numstr_round_repeating+0x7b>
movzbl -0x2(%rbx),%ecx
lea    0x1(%rax),%r12
cmp    -0x1(%rbx),%cl
jne    116a <numstr_round_repeating+0x4a>
cmp    $0x30,%cl
jne    1160 <numstr_round_repeating+0x40>
add    %r15,%rax
jmp    1167 <numstr_round_repeating+0x47>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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