#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 /*<<< orphan*/ sprintf(char *, char *, long long);
double strtod(char *, char **);
double trunc(double);
void progCleanupNumeric(char *s) {
  char *p = NULL;
  double d1 = strtod(s, &p);
  double d2 = trunc(d1);
  long long int i = d2;
  if (*p != 0 || p == s) {
    return;
  }
  if (d1 - d2 == 0) {
    sprintf(s, "%i", i);
  }
}


x86 assembly (clang, -O0):
<progCleanupNumeric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <trunc@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118d <progCleanupNumeric+0x5d>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1192 <progCleanupNumeric+0x62>
jmp    11c3 <progCleanupNumeric+0x93>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c3 <progCleanupNumeric+0x93>
jp     11c3 <progCleanupNumeric+0x93>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe42(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progCleanupNumeric>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
call   1040 <trunc@plt>
mov    (%rsp),%rax
cmp    %rbx,%rax
je     1190 <progCleanupNumeric+0x60>
cmpb   $0x0,(%rax)
jne    1190 <progCleanupNumeric+0x60>
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    1190 <progCleanupNumeric+0x60>
jp     1190 <progCleanupNumeric+0x60>
cvttsd2si %xmm0,%rdx
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define void @progCleanupNumeric(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
%7 = load i8*, i8** %2
%8 = call double @strtod(i8* %7, i8** %3)
store double %8, double* %4
%9 = load double, double* %4
%10 = call double @llvm.trunc.f64(double %9)
store double %10, double* %5
%11 = load double, double* %5
%12 = fptosi double %11 to i64
store i64 %12, i64* %6
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %1
br label %31
22: ; preds = %17
%23 = load double, double* %4
%24 = load double, double* %5
%25 = fsub double %23, %24
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i8*, i8** %2
%29 = load i64, i64* %6
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 %29)
br label %31
31: ; preds = %21, %27, %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define void @progCleanupNumeric(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = call double @strtod(i8* %0, i8** %2)
%5 = tail call double @llvm.trunc.f64(double %4)
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = icmp ne i8* %6, %0
%10 = and i1 %9, %8
%11 = fsub double %4, %5
%12 = fcmp oeq double %11, 0.000000e+00
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = fptosi double %5 to i64
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %17
17: ; preds = %14, %1
ret void
}