#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 uint;

/* Variables and functions */
int strlen(char *);
char toupper(char);
int GetFinalSize(char *ext, uint Size, uint *pValue) {
  char c;
  uint val;
  if (strlen(ext) > 2)
    return -1;
  c = toupper(ext[0]);
  val = ext[1] - '0';
  switch (c) {
  case 'B':
    if ((val + 1) > Size)
      return -1;
    *pValue = 1;
    return (0);
  case 'W':
    if ((val + 2) > Size)
      return -1;
    *pValue = 2;
    return (0);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<GetFinalSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jle    1151 <GetFinalSize+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <GetFinalSize+0xdd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffd0,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x42,%eax
je     1194 <GetFinalSize+0x74>
jmp    1183 <GetFinalSize+0x63>
mov    -0x2c(%rbp),%eax
sub    $0x57,%eax
je     11c5 <GetFinalSize+0xa5>
jmp    11f6 <GetFinalSize+0xd6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jle    11af <GetFinalSize+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <GetFinalSize+0xdd>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11fd <GetFinalSize+0xdd>
mov    -0x28(%rbp),%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
jle    11e0 <GetFinalSize+0xc0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <GetFinalSize+0xdd>
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11fd <GetFinalSize+0xdd>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFinalSize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x2,%eax
jg     1179 <GetFinalSize+0x59>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
movsbl 0x1(%rbx),%ecx
movsbl %al,%eax
cmp    $0x57,%eax
je     1167 <GetFinalSize+0x47>
cmp    $0x42,%eax
jne    1179 <GetFinalSize+0x59>
add    $0xffffffd1,%ecx
mov    $0x1,%eax
cmp    %r15d,%ecx
jle    1174 <GetFinalSize+0x54>
jmp    1179 <GetFinalSize+0x59>
add    $0xffffffd2,%ecx
mov    $0x2,%eax
cmp    %r15d,%ecx
jg     1179 <GetFinalSize+0x59>
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetFinalSize(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %43
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
store i8 %18, i8* %8
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
store i32 %23, i32* %9
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
switch i32 %25, label %42 [
i32 66, label %26
i32 87, label %34
]
26: ; preds = %14
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %6
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -1, i32* %4
br label %43
32: ; preds = %26
%33 = load i32*, i32** %7
store i32 1, i32* %33
store i32 0, i32* %4
br label %43
34: ; preds = %14
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 2
%37 = load i32, i32* %6
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 -1, i32* %4
br label %43
40: ; preds = %34
%41 = load i32*, i32** %7
store i32 2, i32* %41
store i32 0, i32* %4
br label %43
42: ; preds = %14
store i32 -1, i32* %4
br label %43
43: ; preds = %42, %40, %39, %32, %31, %13
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @GetFinalSize(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 2
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = load i8, i8* %0
%8 = tail call signext i8 @toupper(i8 signext %7)
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = sext i8 %8 to i32
switch i32 %12, label %21 [
i32 66, label %13
i32 87, label %16
]
13: ; preds = %6
%14 = add nsw i32 %11, -47
%15 = icmp sgt i32 %14, %1
br i1 %15, label %21, label %19
16: ; preds = %6
%17 = add nsw i32 %11, -46
%18 = icmp sgt i32 %17, %1
br i1 %18, label %21, label %19
19: ; preds = %16, %13
%20 = phi i32 [ 1, %13 ], [ 2, %16 ]
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %6, %16, %13, %3
%22 = phi i32 [ -1, %3 ], [ -1, %13 ], [ -1, %16 ], [ -1, %6 ], [ 0, %19 ]
ret i32 %22
}