#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 strtol(char *, char **, int /*<<< orphan*/);
int num_arg(char *t) {
  int nbr;
  char *tt;
  nbr = strtol(t, &tt, 0);
  if (t != tt) {
    if (*tt == 'k')
      nbr *= 1024;
    else if (*tt == 'M')
      nbr *= 1024 * 1024;
  }
  return nbr;
}


x86 assembly (clang, -O0):
<num_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     117d <num_arg+0x6d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    115a <num_arg+0x4a>
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <num_arg+0x68>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
jne    1173 <num_arg+0x63>
mov    -0xc(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <num_arg+0x68>
jmp    117d <num_arg+0x6d>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_arg>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     1142 <num_arg+0x32>
mov    (%rcx),%cl
cmp    $0x4d,%cl
je     113f <num_arg+0x2f>
cmp    $0x6b,%cl
jne    1142 <num_arg+0x32>
shl    $0xa,%eax
jmp    1142 <num_arg+0x32>
shl    $0x14,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @num_arg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strtol(i8* %5, i8** %4, i32 0)
store i32 %6, i32* %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %4
%9 = icmp ne i8* %7, %8
br i1 %9, label %10, label %28
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 107
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, 1024
store i32 %17, i32* %3
br label %27
18: ; preds = %10
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 77
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %3
%25 = mul nsw i32 %24, 1048576
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %18
br label %27
27: ; preds = %26, %15
br label %28
28: ; preds = %27, %1
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @num_arg(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, %0
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = load i8, i8* %5
switch i8 %8, label %13 [
i8 107, label %9
i8 77, label %11
]
9: ; preds = %7
%10 = shl nsw i32 %4, 10
br label %13
11: ; preds = %7
%12 = shl nsw i32 %4, 20
br label %13
13: ; preds = %7, %9, %11, %1
%14 = phi i32 [ %10, %9 ], [ %12, %11 ], [ %4, %1 ], [ %4, %7 ]
ret i32 %14
}