#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int atoi(char *);
int decimal_number_length(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ snprintf(char *, unsigned int, char *, int, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void cleanup_decimal_str(char *decimal_str, char *cleaned_up_str,
                         unsigned int length) {
  uint32_t value_int, value_frac;
  char *pos;
  uint8_t decimals = 0;
  uint8_t prepend_zeroes;
  char zeroes[8];
  memcpy(cleaned_up_str, decimal_str, length);
  cleaned_up_str[length] = 0;
  pos = strstr(cleaned_up_str, ".");
  if (pos == NULL) {
    value_int = atoi(cleaned_up_str);
    snprintf(cleaned_up_str, length, "%u", value_int);
  } else {
    while ((*(pos + 1 + decimals) >= '0') && (*(pos + 1 + decimals) <= '9')) {
      decimals++;
    }
    value_frac = atoi(pos + 1);
    prepend_zeroes = decimals - decimal_number_length(atoi(pos + 1));
    zeroes[0] = 0;
    while (prepend_zeroes--) {
      strcat(zeroes, "0");
    }
    strncpy(cleaned_up_str, decimal_str, (pos - cleaned_up_str));
    cleaned_up_str[cleaned_up_str - pos] = 0;
    value_int = atoi(cleaned_up_str);
    snprintf(cleaned_up_str, length, "%u.%s%u", value_int, zeroes, value_frac);
  }
}


x86 assembly (clang, -O0):
<cleanup_decimal_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ed <cleanup_decimal_str+0x7d>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
lea    0xe28(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12fb <cleanup_decimal_str+0x18b>
jmp    11f2 <cleanup_decimal_str+0x82>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x39(%rbp)
jl     1223 <cleanup_decimal_str+0xb3>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1233 <cleanup_decimal_str+0xc3>
jmp    1241 <cleanup_decimal_str+0xd1>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f2 <cleanup_decimal_str+0x82>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1050 <decimal_number_length@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
movb   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30(%rbp)
cmp    $0x0,%eax
je     12a2 <cleanup_decimal_str+0x132>
lea    -0x38(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   1080 <strcat@plt>
jmp    1279 <cleanup_decimal_str+0x109>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
lea    -0x38(%rbp),%r8
mov    -0x1c(%rbp),%r9d
lea    0xd10(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup_decimal_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rsi,%rdi
mov    %rbp,%rsi
call   1070 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1264 <cleanup_decimal_str+0xf4>
mov    %rax,%r13
mov    %rbp,0x10(%rsp)
mov    %ebx,0x4(%rsp)
lea    0x1(%rax),%rdi
xor    %ebx,%ebx
movzbl (%rdi,%rbx,1),%eax
add    $0xd0,%al
add    $0x1,%rbx
cmp    $0xa,%al
jb     11c0 <cleanup_decimal_str+0x50>
call   1080 <atoi@plt>
mov    %eax,(%rsp)
mov    %eax,%edi
call   1060 <decimal_number_length@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%eax
movb   $0x0,0x8(%rsp)
cmp    %ebx,%eax
je     120f <cleanup_decimal_str+0x9f>
sub    %ebx,%ebp
add    $0x1,%ebp
lea    0xe09(%rip),%r12
lea    0x8(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
inc    %ebp
jne    1200 <cleanup_decimal_str+0x90>
mov    %r13d,%edx
sub    %r15d,%edx
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
call   1030 <strncpy@plt>
mov    %r15,%rax
sub    %r13,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
call   1080 <atoi@plt>
lea    0xdc6(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %r15,%rdi
mov    0x4(%rsp),%esi
mov    %eax,%ecx
mov    (%rsp),%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1080 <atoi@plt>
lea    0xd94(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%ecx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <snprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [8 x i8] c"%u.%s%u\00"
define void @cleanup_decimal_str(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [8 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %10
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = call i32 @memcpy(i8* %13, i8* %14, i32 %15)
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = call i8* @strstr(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %99
32: ; preds = %3
br label %33
33: ; preds = %53, %32
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i32, i32* %10
%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 sge i32 %40, 48
br i1 %41, label %42, label %51
42: ; preds = %33
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i32, i32* %10
%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 sle i32 %49, 57
br label %51
51: ; preds = %42, %33
%52 = phi i1 [ false, %33 ], [ %50, %42 ]
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %33
56: ; preds = %51
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %8
%60 = load i32, i32* %10
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = call i32 @atoi(i8* %62)
%64 = call i32 @decimal_number_length(i32 %63)
%65 = sub nsw i32 %60, %64
store i32 %65, i32* %11
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
store i8 0, i8* %66
br label %67
67: ; preds = %71, %56
%68 = load i32, i32* %11
%69 = add nsw i32 %68, -1
store i32 %69, i32* %11
%70 = icmp ne i32 %68, 0
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%73 = call i32 @strcat(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %67
74: ; preds = %67
%75 = load i8*, i8** %5
%76 = load i8*, i8** %4
%77 = load i8*, i8** %9
%78 = load i8*, i8** %5
%79 = ptrtoint i8* %77 to i64
%80 = ptrtoint i8* %78 to i64
%81 = sub i64 %79, %80
%82 = trunc i64 %81 to i32
%83 = call i32 @strncpy(i8* %75, i8* %76, i32 %82)
%84 = load i8*, i8** %5
%85 = load i8*, i8** %5
%86 = load i8*, i8** %9
%87 = ptrtoint i8* %85 to i64
%88 = ptrtoint i8* %86 to i64
%89 = sub i64 %87, %88
%90 = getelementptr inbounds i8, i8* %84, i64 %89
store i8 0, i8* %90
%91 = load i8*, i8** %5
%92 = call i32 @atoi(i8* %91)
store i32 %92, i32* %7
%93 = load i8*, i8** %5
%94 = load i32, i32* %6
%95 = load i32, i32* %7
%96 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%97 = load i32, i32* %8
%98 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %93, i32 %94, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %95, i8* %96, i32 %97)
br label %99
99: ; preds = %74, %25
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [8 x i8] c"%u.%s%u\00"
define void @cleanup_decimal_str(i8* %0, i8* %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %2)
%7 = zext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 0, i8* %8
%9 = tail call i8* @strchr(i8* dereferenceable(1) %1, i32 46)
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %9, i64 1
br label %16
13: ; preds = %3
%14 = tail call i32 @atoi(i8* %1)
%15 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %44
16: ; preds = %16, %11
%17 = phi i64 [ %22, %16 ], [ 0, %11 ]
%18 = getelementptr inbounds i8, i8* %12, i64 %17
%19 = load i8, i8* %18
%20 = add i8 %19, -48
%21 = icmp ult i8 %20, 10
%22 = add nuw i64 %17, 1
br i1 %21, label %16, label %23
23: ; preds = %16
%24 = trunc i64 %17 to i32
%25 = tail call i32 @atoi(i8* %12)
%26 = tail call i32 @decimal_number_length(i32 %25)
%27 = sub nsw i32 %24, %26
store i8 0, i8* %5
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %23, %29
%30 = phi i32 [ %31, %29 ], [ %27, %23 ]
%31 = add nsw i32 %30, -1
%32 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i32 %31, 0
br i1 %33, label %34, label %29
34: ; preds = %29, %23
%35 = ptrtoint i8* %9 to i64
%36 = ptrtoint i8* %1 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = call i32 @strncpy(i8* %1, i8* %0, i32 %38)
%40 = sub i64 %36, %35
%41 = getelementptr inbounds i8, i8* %1, i64 %40
store i8 0, i8* %41
%42 = call i32 @atoi(i8* %1)
%43 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %42, i8* %5, i32 %25)
br label %44
44: ; preds = %34, %13
ret void
}