#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*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ strlen(char *);
void sanitize_gaugevalue(char *k) {
  char *dest = malloc(strlen(k) + 1);
  char *p = k;
  int c = 0;
  while (*p != '\0') {
    if (*p == '.' || *p == '-' || *p == '+' || (*p >= '0' && *p <= '9')) {
      *(dest + c) = *p;
      c++;
    }
    p++;
  }
  *(dest + c) = '\0';
  memcpy(k, dest, c + 1);
  if (dest)
    free(dest);
}


x86 assembly (clang, -O0):
<sanitize_gaugevalue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ff <sanitize_gaugevalue+0xbf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11d4 <sanitize_gaugevalue+0x94>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11d4 <sanitize_gaugevalue+0x94>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     11d4 <sanitize_gaugevalue+0x94>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11ee <sanitize_gaugevalue+0xae>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11ee <sanitize_gaugevalue+0xae>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1174 <sanitize_gaugevalue+0x34>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     1232 <sanitize_gaugevalue+0xf2>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_gaugevalue>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
mov    %r14,%rcx
jmp    116d <sanitize_gaugevalue+0x2d>
nop
movslq %eax,%rsi
mov    %dl,(%rbx,%rsi,1)
add    $0x1,%eax
add    $0x1,%rcx
movzbl (%rcx),%edx
lea    -0x2d(%rdx),%esi
cmp    $0x2,%sil
jb     1160 <sanitize_gaugevalue+0x20>
cmp    $0x2b,%dl
je     1160 <sanitize_gaugevalue+0x20>
test   %dl,%dl
je     118d <sanitize_gaugevalue+0x4d>
lea    -0x30(%rdx),%esi
cmp    $0x9,%sil
jbe    1160 <sanitize_gaugevalue+0x20>
jmp    1169 <sanitize_gaugevalue+0x29>
movslq %eax,%rdx
movb   $0x0,(%rbx,%rdx,1)
add    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @sanitize_gaugevalue(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
br label %5
5: ; preds = %16, %1
%6 = phi i8* [ %0, %1 ], [ %18, %16 ]
%7 = phi i32 [ 0, %1 ], [ %17, %16 ]
%8 = load i8, i8* %6
switch i8 %8, label %9 [
i8 0, label %19
i8 46, label %12
i8 45, label %12
i8 43, label %12
]
9: ; preds = %5
%10 = add i8 %8, -48
%11 = icmp ult i8 %10, 10
br i1 %11, label %12, label %16
12: ; preds = %9, %5, %5, %5
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %4, i64 %13
store i8 %8, i8* %14
%15 = add nsw i32 %7, 1
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %15, %12 ], [ %7, %9 ]
%18 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
19: ; preds = %5
%20 = sext i32 %7 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
store i8 0, i8* %21
%22 = add nsw i32 %7, 1
%23 = tail call i32 @memcpy(i8* %0, i8* %4, i32 %22)
%24 = tail call i32 @free(i8* %4)
ret void
}