#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 */
void *strtoul(char const *, char **, int /*<<< orphan*/);
int get_pm_page_spec(const char *s, unsigned int *page_size,
                     unsigned int *num_pages) {
  char *p;
  unsigned long val;
  val = strtoul(s, &p, 0);
  if (p == s)
    return -1;
  if (*p == 'x' && p[1]) {
    *num_pages = val;
    *page_size = strtoul(p + 1, &p, 0);
  } else {
    *num_pages = -1;
    *page_size = val;
  }
  *page_size <<= 10;
  return *p;
}


x86 assembly (clang, -O0):
<get_pm_page_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1151 <get_pm_page_spec+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <get_pm_page_spec+0xb9>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
jne    119e <get_pm_page_spec+0x8e>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     119e <get_pm_page_spec+0x8e>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b4 <get_pm_page_spec+0xa4>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0xa,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pm_page_spec>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    0x8(%rsp),%rdi
cmp    %rbx,%rdi
je     116f <get_pm_page_spec+0x5f>
cmpb   $0x78,(%rdi)
jne    115d <get_pm_page_spec+0x4d>
cmpb   $0x0,0x1(%rdi)
je     115d <get_pm_page_spec+0x4d>
add    $0x1,%rdi
mov    %eax,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    0x8(%rsp),%rdi
jmp    1164 <get_pm_page_spec+0x54>
movl   $0xffffffff,(%r15)
shl    $0xa,%eax
mov    %eax,(%r14)
movsbl (%rdi),%eax
jmp    1174 <get_pm_page_spec+0x64>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_pm_page_spec(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i8* @strtoul(i8* %10, i8** %8, i32 0)
%12 = ptrtoint i8* %11 to i64
store i64 %12, i64* %9
%13 = load i8*, i8** %8
%14 = load i8*, i8** %5
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %49
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 120
br i1 %21, label %22, label %37
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %22
%29 = load i64, i64* %9
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %7
store i32 %30, i32* %31
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i8* @strtoul(i8* %33, i8** %8, i32 0)
%35 = ptrtoint i8* %34 to i32
%36 = load i32*, i32** %6
store i32 %35, i32* %36
br label %42
37: ; preds = %22, %17
%38 = load i32*, i32** %7
store i32 -1, i32* %38
%39 = load i64, i64* %9
%40 = trunc i64 %39 to i32
%41 = load i32*, i32** %6
store i32 %40, i32* %41
br label %42
42: ; preds = %37, %28
%43 = load i32*, i32** %6
%44 = load i32, i32* %43
%45 = shl i32 %44, 10
store i32 %45, i32* %43
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
store i32 %48, i32* %4
br label %49
49: ; preds = %42, %16
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @get_pm_page_spec(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i8* @strtoul(i8* %0, i8** %4, i32 0)
%7 = ptrtoint i8* %6 to i64
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, %0
br i1 %9, label %30, label %10
10: ; preds = %3
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 120
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = trunc i64 %7 to i32
store i32 %18, i32* %2
%19 = call i8* @strtoul(i8* %14, i8** %4, i32 0)
%20 = ptrtoint i8* %19 to i64
%21 = load i8*, i8** %4
br label %23
22: ; preds = %13, %10
store i32 -1, i32* %2
br label %23
23: ; preds = %22, %17
%24 = phi i8* [ %8, %22 ], [ %21, %17 ]
%25 = phi i64 [ %7, %22 ], [ %20, %17 ]
%26 = trunc i64 %25 to i32
%27 = shl i32 %26, 10
store i32 %27, i32* %1
%28 = load i8, i8* %24
%29 = sext i8 %28 to i32
br label %30
30: ; preds = %3, %23
%31 = phi i32 [ %29, %23 ], [ -1, %3 ]
ret i32 %31
}