#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*/ fprintf(int /*<<< orphan*/, char *, char, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stderr;
char tolower(char);
int unformatvalue(char *s) {
  char c = '-';
  int val;
  sscanf(s, "%d%c", &val, &c);
  if (c == '-')
    return val;
  c = tolower(c);
  if (c == 'k')
    return val * 1024;
  else if (c == 'm')
    return val * 1024 * 1024;
  else {
    fprintf(stderr, "WARNING: %c: Unknown size specifier in '%s'\n", c, s);
    return val;
  }
  return val;
}


x86 assembly (clang, -O0):
<unformatvalue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x2d,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x11(%rbp),%rcx
call   1050 <sscanf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    1170 <unformatvalue+0x40>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <unformatvalue+0xaa>
movsbl -0x11(%rbp),%edi
call   1040 <tolower@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x6b,%eax
jne    1197 <unformatvalue+0x67>
mov    -0x18(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11da <unformatvalue+0xaa>
movsbl -0x11(%rbp),%eax
cmp    $0x6d,%eax
jne    11b5 <unformatvalue+0x85>
mov    -0x18(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11da <unformatvalue+0xaa>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rcx
lea    0xe39(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unformatvalue>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x2d,0xb(%rsp)
lea    0xebc(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0xb(%rsp),%rcx
call   1050 <sscanf@plt>
mov    0xb(%rsp),%al
cmp    $0x2d,%al
je     119c <unformatvalue+0x6c>
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,0xb(%rsp)
cmp    $0x6d,%al
je     1178 <unformatvalue+0x48>
cmp    $0x6b,%al
jne    1181 <unformatvalue+0x51>
mov    0xc(%rsp),%eax
shl    $0xa,%eax
jmp    11a0 <unformatvalue+0x70>
mov    0xc(%rsp),%eax
shl    $0x14,%eax
jmp    11a0 <unformatvalue+0x70>
mov    0x2e58(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xe71(%rip),%rsi
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"WARNING: %c: Unknown size specifier in '%s'\0A\00"
define i32 @unformatvalue(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %3
store i8 45, i8* %4
%6 = load i8*, i8** %3
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5, i8* %4)
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 45
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %5
store i32 %12, i32* %2
br label %36
13: ; preds = %1
%14 = load i8, i8* %4
%15 = call signext i8 @tolower(i8 signext %14)
store i8 %15, i8* %4
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 107
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 1024
store i32 %21, i32* %2
br label %36
22: ; preds = %13
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 109
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %5
%28 = mul nsw i32 %27, 1024
%29 = mul nsw i32 %28, 1024
store i32 %29, i32* %2
br label %36
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i8, i8* %4
%33 = load i8*, i8** %3
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8 signext %32, i8* %33)
%35 = load i32, i32* %5
store i32 %35, i32* %2
br label %36
36: ; preds = %30, %26, %19, %11
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%c\00"
@stderr = global i32 0
@.str.1 = [45 x i8] c"WARNING: %c: Unknown size specifier in '%s'\0A\00"
define i32 @unformatvalue(i8* %0) {
%2 = alloca i8
%3 = alloca i32
store i8 45, i8* %2
%4 = bitcast i32* %3 to i8*
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %2)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 45
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %3
br label %22
10: ; preds = %1
%11 = call signext i8 @tolower(i8 signext %6)
store i8 %11, i8* %2
switch i8 %11, label %18 [
i8 107, label %12
i8 109, label %15
]
12: ; preds = %10
%13 = load i32, i32* %3
%14 = shl nsw i32 %13, 10
br label %22
15: ; preds = %10
%16 = load i32, i32* %3
%17 = shl nsw i32 %16, 20
br label %22
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8 signext %11, i8* %0)
%21 = load i32, i32* %3
br label %22
22: ; preds = %18, %15, %12, %8
%23 = phi i32 [ %9, %8 ], [ %14, %12 ], [ %17, %15 ], [ %21, %18 ]
ret i32 %23
}