#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*/ sscanf(char const *, char *, char *);
char *strdup(char *);
char *mon_val_brut(const char *str) {
  char tmp[80];
  char *r = tmp;
  char *w = tmp;
  sscanf(str, "%[+-0123456789,. D]", tmp);
  while (*r != '\0') {
    if (*r != ',')
      *w++ = *r;
    ++r;
  }
  *w = *r;
  return strdup(tmp);
}


x86 assembly (clang, -O0):
<mon_val_brut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xeb5(%rip),%rsi
call   1030 <sscanf@plt>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1198 <mon_val_brut+0x78>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1187 <mon_val_brut+0x67>
mov    -0x68(%rbp),%rax
mov    (%rax),%cl
mov    -0x70(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x70(%rbp)
mov    %cl,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1150 <mon_val_brut+0x30>
mov    -0x68(%rbp),%rax
mov    (%rax),%cl
mov    -0x70(%rbp),%rax
mov    %cl,(%rax)
lea    -0x60(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mon_val_brut>:
push   %rbx
sub    $0x50,%rsp
mov    %rsp,%rbx
lea    0xed1(%rip),%rsi
mov    %rbx,%rdx
call   1030 <sscanf@plt>
mov    %rbx,%rax
jmp    1144 <mon_val_brut+0x24>
nopl   0x0(%rax)
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x2c,%cl
je     1140 <mon_val_brut+0x20>
test   %cl,%cl
je     1158 <mon_val_brut+0x38>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    1140 <mon_val_brut+0x20>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%[+-0123456789,. D]\00"
define i8* @mon_val_brut(i8* %0) {
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
store i8* %6, i8** %4
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %5
%8 = load i8*, i8** %2
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %26, %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 %29
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 44
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
store i8 %23, i8* %24
br label %26
26: ; preds = %21, %16
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %11
29: ; preds = %11
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
store i8 %31, i8* %32
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%34 = call i8* @strdup(i8* %33)
ret i8* %34
}

LLVM IR (-O2):
@.str = [20 x i8] c"%[+-0123456789,. D]\00"
define noalias i8* @mon_val_brut(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %5
5: ; preds = %11, %1
%6 = phi i8* [ %3, %1 ], [ %13, %11 ]
%7 = phi i8* [ %3, %1 ], [ %12, %11 ]
%8 = load i8, i8* %6
switch i8 %8, label %9 [
i8 0, label %14
i8 44, label %11
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %8, i8* %7
br label %11
11: ; preds = %5, %9
%12 = phi i8* [ %10, %9 ], [ %7, %5 ]
%13 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
14: ; preds = %5
store i8 0, i8* %7
%15 = call i8* @strdup(i8* %3)
ret i8* %15
}