#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*/ isdigit(unsigned char);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int strtoul(char *, char **, int);
int sigar_cpu_mhz_from_model(char *model) {
  int mhz = -1;
  char *ptr = model;
  while (*ptr && (ptr = strchr(ptr, ' '))) {
    while (*ptr && !(isdigit(((unsigned char)(*ptr))))) {
      ptr++;
    }
    mhz = strtoul(ptr, &ptr, 10);
    if (*ptr == '.') {
      ++ptr;
      mhz *= 100;
      mhz += strtoul(ptr, &ptr, 10);
      break;
    } else if ((strncmp(ptr, "GHz", 3) == 0) || (strncmp(ptr, "MHz", 3) == 0)) {
      break;
    } else {
      mhz = -1;
    }
  }
  if (mhz != -1) {
    if ((strncmp(ptr, "GHz", 3) == 0)) {
      mhz *= 10;
    }
  }
  return mhz;
}


x86 assembly (clang, -O0):
<sigar_cpu_mhz_from_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     118c <sigar_cpu_mhz_from_model+0x4c>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119c <sigar_cpu_mhz_from_model+0x5c>
jmp    1297 <sigar_cpu_mhz_from_model+0x157>
jmp    11a1 <sigar_cpu_mhz_from_model+0x61>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
je     11cd <sigar_cpu_mhz_from_model+0x8d>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11dd <sigar_cpu_mhz_from_model+0x9d>
jmp    11ee <sigar_cpu_mhz_from_model+0xae>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <sigar_cpu_mhz_from_model+0x61>
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1243 <sigar_cpu_mhz_from_model+0x103>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
imul   $0x64,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1297 <sigar_cpu_mhz_from_model+0x157>
mov    -0x18(%rbp),%rdi
lea    0xdb2(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1281 <sigar_cpu_mhz_from_model+0x141>
mov    -0x18(%rbp),%rdi
lea    0xd97(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1286 <sigar_cpu_mhz_from_model+0x146>
jmp    1297 <sigar_cpu_mhz_from_model+0x157>
movl   $0xffffffff,-0xc(%rbp)
jmp    1292 <sigar_cpu_mhz_from_model+0x152>
jmp    115b <sigar_cpu_mhz_from_model+0x1b>
cmpl   $0xffffffff,-0xc(%rbp)
je     12cc <sigar_cpu_mhz_from_model+0x18c>
mov    -0x18(%rbp),%rdi
lea    0xd54(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12c7 <sigar_cpu_mhz_from_model+0x187>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    12cc <sigar_cpu_mhz_from_model+0x18c>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigar_cpu_mhz_from_model>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    %rsp,%r14
lea    0xea8(%rip),%r15
lea    0xea5(%rip),%r12
mov    $0xffffffff,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x0,0x0(%rbp)
je     122e <sigar_cpu_mhz_from_model+0xee>
mov    %rbp,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     122e <sigar_cpu_mhz_from_model+0xee>
mov    %rax,%rbx
mov    (%rax),%al
test   %al,%al
je     11b8 <sigar_cpu_mhz_from_model+0x78>
nopl   0x0(%rax)
movzbl %al,%edi
call   1040 <isdigit@plt>
test   %eax,%eax
jne    11b8 <sigar_cpu_mhz_from_model+0x78>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <sigar_cpu_mhz_from_model+0x60>
mov    %rbx,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebx
mov    (%rsp),%rbp
cmpb   $0x2e,0x0(%rbp)
je     1240 <sigar_cpu_mhz_from_model+0x100>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1206 <sigar_cpu_mhz_from_model+0xc6>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <sigar_cpu_mhz_from_model+0x30>
cmp    $0xffffffff,%ebx
je     122e <sigar_cpu_mhz_from_model+0xee>
mov    (%rsp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
lea    (%rbx,%rbx,1),%ecx
test   %rax,%rax
lea    (%rcx,%rcx,4),%r13d
cmovne %ebx,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%rbp
mov    %rbp,(%rsp)
imul   $0x64,%ebx,%r14d
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebx
add    %r14d,%ebx
cmp    $0xffffffff,%ebx
jne    120b <sigar_cpu_mhz_from_model+0xcb>
jmp    122e <sigar_cpu_mhz_from_model+0xee>

LLVM IR (-O0):
@.str = [4 x i8] c"GHz\00"
@.str.1 = [4 x i8] c"MHz\00"
define i32 @sigar_cpu_mhz_from_model(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 -1, i32* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %61, %1
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i8*, i8** %4
%13 = call i8* @strchr(i8* %12, i8 signext 32)
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br label %15
15: ; preds = %11, %6
%16 = phi i1 [ false, %6 ], [ %14, %11 ]
br i1 %16, label %17, label %62
17: ; preds = %15
br label %18
18: ; preds = %31, %17
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @isdigit(i8 zeroext %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br label %29
29: ; preds = %23, %18
%30 = phi i1 [ false, %18 ], [ %28, %23 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
br label %18
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = call i32 @strtoul(i8* %35, i8** %4, i32 10)
store i32 %36, i32* %3
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 46
br i1 %40, label %41, label %50
41: ; preds = %34
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
%44 = load i32, i32* %3
%45 = mul nsw i32 %44, 100
store i32 %45, i32* %3
%46 = load i8*, i8** %4
%47 = call i32 @strtoul(i8* %46, i8** %4, i32 10)
%48 = load i32, i32* %3
%49 = add nsw i32 %48, %47
store i32 %49, i32* %3
br label %62
50: ; preds = %34
%51 = load i8*, i8** %4
%52 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%53 = icmp eq i64 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i8*, i8** %4
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54, %50
br label %62
59: ; preds = %54
store i32 -1, i32* %3
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %6
62: ; preds = %58, %41, %15
%63 = load i32, i32* %3
%64 = icmp ne i32 %63, -1
br i1 %64, label %65, label %73
65: ; preds = %62
%66 = load i8*, i8** %4
%67 = call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = load i32, i32* %3
%71 = mul nsw i32 %70, 10
store i32 %71, i32* %3
br label %72
72: ; preds = %69, %65
br label %73
73: ; preds = %72, %62
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [4 x i8] c"GHz\00"
@.str.1 = [4 x i8] c"MHz\00"
define i32 @sigar_cpu_mhz_from_model(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
br label %4
4: ; preds = %37, %1
%5 = phi i8* [ %26, %37 ], [ %0, %1 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %49, label %8
8: ; preds = %4
%9 = tail call i8* @strchr(i8* %5, i8 signext 32)
%10 = icmp eq i8* %9, null
br i1 %10, label %49, label %11
11: ; preds = %8
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %11, %19
%15 = phi i8 [ %21, %19 ], [ %12, %11 ]
%16 = phi i8* [ %20, %19 ], [ %9, %11 ]
%17 = tail call i32 @isdigit(i8 zeroext %15)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %19, %11
%24 = phi i8* [ %9, %11 ], [ %20, %19 ], [ %16, %14 ]
store i8* %24, i8** %2
%25 = call i32 @strtoul(i8* %24, i8** %2, i32 10)
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 46
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %30, i8** %2
%31 = mul nsw i32 %25, 100
%32 = call i32 @strtoul(i8* %30, i8** %2, i32 10)
%33 = add nsw i32 %32, %31
br label %40
34: ; preds = %23
%35 = tail call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = tail call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %4
40: ; preds = %34, %37, %29
%41 = phi i32 [ %33, %29 ], [ %25, %37 ], [ %25, %34 ]
%42 = icmp eq i32 %41, -1
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = load i8*, i8** %2
%45 = tail call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%46 = icmp eq i64 %45, 0
%47 = mul nsw i32 %41, 10
%48 = select i1 %46, i32 %47, i32 %41
br label %49
49: ; preds = %4, %8, %43, %40
%50 = phi i32 [ -1, %40 ], [ %48, %43 ], [ -1, %8 ], [ -1, %4 ]
ret i32 %50
}