#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 */
typedef int int8_t;

/* Variables and functions */
int sscanf(char *, char *, unsigned int *, int *);
int getNum(char *str, unsigned *val, int8_t *opt) {
  int f, n;
  unsigned v;
  *opt = 0;
  f = sscanf(str, " %i %n", &v, &n);
  if (f == 1) {
    *val = v;
    *opt = 1;
    return n;
  }
  f = sscanf(str, " v%i %n", &v, &n);
  if (f == 1) {
    *val = v;
    if (v < 150)
      *opt = 2;
    else
      *opt = -2;
    return n;
  }
  f = sscanf(str, " p%i %n", &v, &n);
  if (f == 1) {
    *val = v;
    if (v < 10)
      *opt = 3;
    else
      *opt = -3;
    return n;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xec7(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1171 <getNum+0x61>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <getNum+0x123>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    11d0 <getNum+0xc0>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x96,-0x2c(%rbp)
jae    11bb <getNum+0xab>
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
jmp    11c5 <getNum+0xb5>
mov    -0x20(%rbp),%rax
movl   $0xfffffffe,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <getNum+0x123>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    122c <getNum+0x11c>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0xa,-0x2c(%rbp)
jae    1217 <getNum+0x107>
mov    -0x20(%rbp),%rax
movl   $0x3,(%rax)
jmp    1221 <getNum+0x111>
mov    -0x20(%rbp),%rax
movl   $0xfffffffd,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <getNum+0x123>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rdx)
lea    0xed1(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1153 <getNum+0x43>
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
movl   $0x1,(%r15)
jmp    11ca <getNum+0xba>
lea    0xead(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    118e <getNum+0x7e>
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
xor    %ecx,%ecx
cmp    $0x96,%eax
setb   %cl
lea    -0x2(,%rcx,4),%eax
mov    %eax,(%r15)
jmp    11ca <getNum+0xba>
lea    0xe7a(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    11ce <getNum+0xbe>
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
cmp    $0xa,%eax
mov    $0x3,%eax
mov    $0xfffffffd,%ecx
cmovb  %eax,%ecx
mov    %ecx,(%r15)
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c" %i %n\00"
@.str.1 = [8 x i8] c" v%i %n\00"
@.str.2 = [8 x i8] c" p%i %n\00"
define i32 @getNum(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%11 = load i32*, i32** %7
store i32 0, i32* %11
%12 = load i8*, i8** %5
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %9)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* %10
%18 = load i32*, i32** %6
store i32 %17, i32* %18
%19 = load i32*, i32** %7
store i32 1, i32* %19
%20 = load i32, i32* %9
store i32 %20, i32* %4
br label %54
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32* %9)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %37
26: ; preds = %21
%27 = load i32, i32* %10
%28 = load i32*, i32** %6
store i32 %27, i32* %28
%29 = load i32, i32* %10
%30 = icmp ult i32 %29, 150
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i32*, i32** %7
store i32 2, i32* %32
br label %35
33: ; preds = %26
%34 = load i32*, i32** %7
store i32 -2, i32* %34
br label %35
35: ; preds = %33, %31
%36 = load i32, i32* %9
store i32 %36, i32* %4
br label %54
37: ; preds = %21
%38 = load i8*, i8** %5
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %9)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %53
42: ; preds = %37
%43 = load i32, i32* %10
%44 = load i32*, i32** %6
store i32 %43, i32* %44
%45 = load i32, i32* %10
%46 = icmp ult i32 %45, 10
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load i32*, i32** %7
store i32 3, i32* %48
br label %51
49: ; preds = %42
%50 = load i32*, i32** %7
store i32 -3, i32* %50
br label %51
51: ; preds = %49, %47
%52 = load i32, i32* %9
store i32 %52, i32* %4
br label %54
53: ; preds = %37
store i32 0, i32* %4
br label %54
54: ; preds = %53, %51, %35, %16
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [7 x i8] c" %i %n\00"
@.str.1 = [8 x i8] c" v%i %n\00"
@.str.2 = [8 x i8] c" p%i %n\00"
define i32 @getNum(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %2
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %4)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
store i32 %11, i32* %1
store i32 1, i32* %2
%12 = load i32, i32* %4
br label %29
13: ; preds = %3
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %4)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %5
store i32 %17, i32* %1
%18 = icmp ult i32 %17, 150
%19 = select i1 %18, i32 2, i32 -2
store i32 %19, i32* %2
%20 = load i32, i32* %4
br label %29
21: ; preds = %13
%22 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %4)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* %5
store i32 %25, i32* %1
%26 = icmp ult i32 %25, 10
%27 = select i1 %26, i32 3, i32 -3
store i32 %27, i32* %2
%28 = load i32, i32* %4
br label %29
29: ; preds = %21, %24, %16, %10
%30 = phi i32 [ %12, %10 ], [ %20, %16 ], [ %28, %24 ], [ 0, %21 ]
ret i32 %30
}