#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 */
unsigned int strtol(char *, char **, int);
unsigned argtoi(char *s, unsigned def) {
  char *p;
  unsigned n = strtol(s, &p, 10), f = 1;
  switch (*p) {
  case 'K':
    f = 1000;
    break;
  case 'M':
    f = 1000000;
    break;
  case 'G':
    f = 1000000000;
    break;
  case 'k':
    f = (1u << 10);
    break;
  case 'm':
    f = (1u << 20);
    break;
  case 'g':
    f = (1u << 30);
    break;
  case 'b':
    return 1u << n;
  default:
    f = def;
  }
  return n * f;
}


x86 assembly (clang, -O0):
<argtoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x26,%eax
ja     11c2 <argtoi+0xb2>
mov    -0x30(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x3e8,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
movl   $0xf4240,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
movl   $0x3b9aca00,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
movl   $0x400,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
movl   $0x100000,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
movl   $0x40000000,-0x28(%rbp)
jmp    11c8 <argtoi+0xb8>
mov    -0x24(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <argtoi+0xc2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argtoi>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
movsbl (%rcx),%ecx
add    $0xffffffb9,%ecx
cmp    $0x26,%ecx
ja     1152 <argtoi+0x42>
mov    $0x3e8,%edx
lea    0xebe(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    $0x3b9aca00,%edx
jmp    117b <argtoi+0x6b>
mov    %ebx,%edx
jmp    117b <argtoi+0x6b>
mov    $0xf4240,%edx
jmp    117b <argtoi+0x6b>
mov    $0x1,%edx
mov    %eax,%ecx
shl    %cl,%edx
jmp    117e <argtoi+0x6e>
mov    $0x400,%edx
jmp    117b <argtoi+0x6b>
mov    $0x100000,%edx
jmp    117b <argtoi+0x6b>
mov    $0x40000000,%edx
imul   %eax,%edx
mov    %edx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @argtoi(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @strtol(i8* %9, i8** %6, i32 10)
store i32 %10, i32* %7
store i32 1, i32* %8
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %23 [
i32 75, label %14
i32 77, label %15
i32 71, label %16
i32 107, label %17
i32 109, label %18
i32 103, label %19
i32 98, label %20
]
14: ; preds = %2
store i32 1000, i32* %8
br label %25
15: ; preds = %2
store i32 1000000, i32* %8
br label %25
16: ; preds = %2
store i32 1000000000, i32* %8
br label %25
17: ; preds = %2
store i32 1024, i32* %8
br label %25
18: ; preds = %2
store i32 1048576, i32* %8
br label %25
19: ; preds = %2
store i32 1073741824, i32* %8
br label %25
20: ; preds = %2
%21 = load i32, i32* %7
%22 = shl i32 1, %21
store i32 %22, i32* %3
br label %29
23: ; preds = %2
%24 = load i32, i32* %5
store i32 %24, i32* %8
br label %25
25: ; preds = %23, %19, %18, %17, %16, %15, %14
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = mul i32 %26, %27
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %20
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @argtoi(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %16 [
i32 75, label %17
i32 77, label %9
i32 71, label %10
i32 107, label %11
i32 109, label %12
i32 103, label %13
i32 98, label %14
]
9: ; preds = %2
br label %17
10: ; preds = %2
br label %17
11: ; preds = %2
br label %17
12: ; preds = %2
br label %17
13: ; preds = %2
br label %17
14: ; preds = %2
%15 = shl nuw i32 1, %5
br label %20
16: ; preds = %2
br label %17
17: ; preds = %2, %16, %13, %12, %11, %10, %9
%18 = phi i32 [ %1, %16 ], [ 1073741824, %13 ], [ 1048576, %12 ], [ 1024, %11 ], [ 1000000000, %10 ], [ 1000000, %9 ], [ 1000, %2 ]
%19 = mul i32 %18, %5
br label %20
20: ; preds = %17, %14
%21 = phi i32 [ %19, %17 ], [ %15, %14 ]
ret i32 %21
}