#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 sscanf(char const *, char *, unsigned int *, char *);
unsigned long long parse_card(const char *card_str) {
  unsigned long long card = 0x0;
  unsigned rank;
  char suit;
  int retval = sscanf(card_str, "%u %c", &rank, &suit);
  if (retval < 2 || !rank || rank > 13) {
    return 0;
  }
  card = 1 << (rank - 1);
  switch (suit) {
  case 'c':
    break;
  case 'd':
    card <<= 13;
    break;
  case 'h':
    card <<= 26;
    break;
  case 's':
    card <<= 39;
    break;
  default:
    return 0;
  }
  return card;
}


x86 assembly (clang, -O0):
<parse_card>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xf15(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x1d(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jl     115d <parse_card+0x4d>
cmpl   $0x0,-0x1c(%rbp)
je     115d <parse_card+0x4d>
cmpl   $0xd,-0x1c(%rbp)
jbe    116a <parse_card+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <parse_card+0xe4>
mov    -0x1c(%rbp),%cl
add    $0xff,%cl
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x18(%rbp)
movsbl -0x1d(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x10,%eax
ja     11df <parse_card+0xcf>
mov    -0x30(%rbp),%rax
lea    0xe62(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11ec <parse_card+0xdc>
mov    -0x18(%rbp),%rax
shl    $0xd,%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <parse_card+0xdc>
mov    -0x18(%rbp),%rax
shl    $0x1a,%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <parse_card+0xdc>
mov    -0x18(%rbp),%rax
shl    $0x27,%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <parse_card+0xdc>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <parse_card+0xe4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_card>:
push   %rax
lea    0xf2c(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
jl     1179 <parse_card+0x69>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
je     1179 <parse_card+0x69>
cmp    $0xd,%ecx
ja     1179 <parse_card+0x69>
add    $0xff,%cl
mov    $0x1,%edx
shl    %cl,%edx
movsbl 0x3(%rsp),%ecx
xor    %eax,%eax
add    $0xffffff9d,%ecx
cmp    $0x10,%ecx
ja     1179 <parse_card+0x69>
lea    0xea3(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
shl    $0xd,%rdx
jmp    1176 <parse_card+0x66>
shl    $0x1a,%rdx
jmp    1176 <parse_card+0x66>
shl    $0x27,%rdx
mov    %rdx,%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%u %c\00"
define i64 @parse_card(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i64 0, i64* %4
%8 = load i8*, i8** %3
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %5, i8* %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 2
br i1 %11, label %18, label %12
12: ; preds = %1
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp ugt i32 %16, 13
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %1
store i64 0, i64* %2
br label %39
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sub i32 %20, 1
%22 = shl i32 1, %21
%23 = sext i32 %22 to i64
store i64 %23, i64* %4
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
switch i32 %25, label %36 [
i32 99, label %26
i32 100, label %27
i32 104, label %30
i32 115, label %33
]
26: ; preds = %19
br label %37
27: ; preds = %19
%28 = load i64, i64* %4
%29 = shl i64 %28, 13
store i64 %29, i64* %4
br label %37
30: ; preds = %19
%31 = load i64, i64* %4
%32 = shl i64 %31, 26
store i64 %32, i64* %4
br label %37
33: ; preds = %19
%34 = load i64, i64* %4
%35 = shl i64 %34, 39
store i64 %35, i64* %4
br label %37
36: ; preds = %19
store i64 0, i64* %2
br label %39
37: ; preds = %33, %30, %27, %26
%38 = load i64, i64* %4
store i64 %38, i64* %2
br label %39
39: ; preds = %37, %36, %18
%40 = load i64, i64* %2
ret i64 %40
}

LLVM IR (-O2):
@.str = [6 x i8] c"%u %c\00"
define i64 @parse_card(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %3)
%6 = icmp slt i32 %5, 2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
%9 = select i1 %6, i1 true, i1 %8
%10 = icmp ugt i32 %7, 13
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %26, label %12
12: ; preds = %1
%13 = add nsw i32 %7, -1
%14 = shl nuw nsw i32 1, %13
%15 = zext i32 %14 to i64
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
switch i32 %17, label %26 [
i32 99, label %24
i32 100, label %18
i32 104, label %20
i32 115, label %22
]
18: ; preds = %12
%19 = shl nuw nsw i64 %15, 13
br label %24
20: ; preds = %12
%21 = shl nuw nsw i64 %15, 26
br label %24
22: ; preds = %12
%23 = shl nuw nsw i64 %15, 39
br label %24
24: ; preds = %22, %20, %18, %12
%25 = phi i64 [ %23, %22 ], [ %21, %20 ], [ %19, %18 ], [ %15, %12 ]
br label %26
26: ; preds = %12, %1, %24
%27 = phi i64 [ %25, %24 ], [ 0, %1 ], [ 0, %12 ]
ret i64 %27
}