#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int strlen(char *);
int /*<<< orphan*/ usage();
int getOptNum(int argc, char **argv, int *pi, int *pj, int *pk) {
  int n, c;
  if (++(*pi) >= argc) {
    usage();
    exit(1);
  }
  n = atoi(argv[*pi]);
  c = argv[*pi][strlen(argv[*pi]) - 1];
  switch (c) {
  case 'K':
    n = n * 1024;
    break;
  case 'M':
    n = n * 1024 * 1024;
    break;
  }
  *pj = *pk = 0;
  return n;
}


x86 assembly (clang, -O0):
<getOptNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
mov    (%rcx),%eax
add    $0x1,%eax
mov    %eax,(%rcx)
cmp    -0x4(%rbp),%eax
jl     1180 <getOptNum+0x40>
mov    $0x0,%al
call   1040 <usage@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    %rdi,-0x40(%rbp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x4b,%eax
je     11e7 <getOptNum+0xa7>
jmp    11d6 <getOptNum+0x96>
mov    -0x34(%rbp),%eax
sub    $0x4d,%eax
je     11f5 <getOptNum+0xb5>
jmp    1201 <getOptNum+0xc1>
mov    -0x2c(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x2c(%rbp)
jmp    1201 <getOptNum+0xc1>
mov    -0x2c(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getOptNum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
movslq (%rdx),%rax
lea    0x1(%rax),%ecx
mov    %ecx,(%rdx)
cmp    %edi,%ecx
jge    11a4 <getOptNum+0x64>
mov    %r8,%r14
mov    0x8(%rsi,%rax,8),%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%eax
cmp    $0x4d,%eax
je     1186 <getOptNum+0x46>
cmp    $0x4b,%eax
jne    1189 <getOptNum+0x49>
shl    $0xa,%ebp
jmp    1189 <getOptNum+0x49>
shl    $0x14,%ebp
movl   $0x0,(%r14)
movl   $0x0,(%r15)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <usage@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define i32 @getOptNum(i32 %0, i8** %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i32*, i32** %8
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = load i32, i32* %6
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = call i32 (...) @usage()
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %5
%22 = load i8**, i8*** %7
%23 = load i32*, i32** %8
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %22, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %11
%29 = load i8**, i8*** %7
%30 = load i32*, i32** %8
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %7
%36 = load i32*, i32** %8
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %35, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %34, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
store i32 %46, i32* %12
%47 = load i32, i32* %12
switch i32 %47, label %55 [
i32 75, label %48
i32 77, label %51
]
48: ; preds = %21
%49 = load i32, i32* %11
%50 = mul nsw i32 %49, 1024
store i32 %50, i32* %11
br label %55
51: ; preds = %21
%52 = load i32, i32* %11
%53 = mul nsw i32 %52, 1024
%54 = mul nsw i32 %53, 1024
store i32 %54, i32* %11
br label %55
55: ; preds = %21, %51, %48
%56 = load i32*, i32** %10
store i32 0, i32* %56
%57 = load i32*, i32** %9
store i32 0, i32* %57
%58 = load i32, i32* %11
ret i32 %58
}

LLVM IR (-O2):
define i32 @getOptNum(i32 %0, i8** nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
%8 = icmp slt i32 %7, %0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i32 (...) @usage()
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call i32 @strlen(i8* %15)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %27 [
i32 75, label %23
i32 77, label %25
]
23: ; preds = %12
%24 = shl nsw i32 %16, 10
br label %27
25: ; preds = %12
%26 = shl nsw i32 %16, 20
br label %27
27: ; preds = %12, %25, %23
%28 = phi i32 [ %16, %12 ], [ %26, %25 ], [ %24, %23 ]
store i32 0, i32* %4
store i32 0, i32* %3
ret i32 %28
}