#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 */
scalar_t__ is_hearts(char);
scalar_t__ is_queen_of_spades(char *);
int calculate_trick(char *card[]) {
  int score = 0;
  for (int i = 0; i < 4; i++) {
    if (is_hearts(*card[i]))
      score += 1;
    else if (is_queen_of_spades(*card))
      score += 13;
  }
  return score;
}


x86 assembly (clang, -O0):
<calculate_trick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11a7 <calculate_trick+0x87>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%edi
call   1030 <is_hearts@plt>
cmp    $0x0,%rax
je     1170 <calculate_trick+0x50>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <calculate_trick+0x74>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <is_queen_of_spades@plt>
cmp    $0x0,%rax
je     118f <calculate_trick+0x6f>
mov    -0xc(%rbp),%eax
add    $0xd,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <calculate_trick+0x74>
jmp    1199 <calculate_trick+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <calculate_trick+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_trick>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rax
movsbl (%rax),%edi
call   1030 <is_hearts@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1151 <calculate_trick+0x31>
mov    (%r14),%rdi
call   1040 <is_queen_of_spades@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0xd,%ebx
cmove  %ecx,%ebx
mov    0x8(%r14),%rax
movsbl (%rax),%edi
call   1030 <is_hearts@plt>
test   %rax,%rax
je     1167 <calculate_trick+0x47>
add    $0x1,%ebx
jmp    117a <calculate_trick+0x5a>
mov    (%r14),%rdi
call   1040 <is_queen_of_spades@plt>
lea    0xd(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
mov    0x10(%r14),%rax
movsbl (%rax),%edi
call   1030 <is_hearts@plt>
test   %rax,%rax
je     1190 <calculate_trick+0x70>
add    $0x1,%ebx
jmp    11a3 <calculate_trick+0x83>
mov    (%r14),%rdi
call   1040 <is_queen_of_spades@plt>
lea    0xd(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
mov    0x18(%r14),%rax
movsbl (%rax),%edi
call   1030 <is_hearts@plt>
test   %rax,%rax
je     11b9 <calculate_trick+0x99>
add    $0x1,%ebx
jmp    11cc <calculate_trick+0xac>
mov    (%r14),%rdi
call   1040 <is_queen_of_spades@plt>
lea    0xd(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @calculate_trick(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %30, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %33
8: ; preds = %5
%9 = load i8**, i8*** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %9, i64 %11
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = call i64 @is_hearts(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %29
20: ; preds = %8
%21 = load i8**, i8*** %2
%22 = load i8*, i8** %21
%23 = call i64 @is_queen_of_spades(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 13
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %20
br label %29
29: ; preds = %28, %17
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %5
33: ; preds = %5
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @calculate_trick(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = tail call i64 @is_hearts(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i8*, i8** %0
%8 = tail call i64 @is_queen_of_spades(i8* %7)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i32 0, i32 13
br label %11
11: ; preds = %1, %6
%12 = phi i32 [ %10, %6 ], [ 1, %1 ]
%13 = getelementptr inbounds i8*, i8** %0, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = tail call i64 @is_hearts(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = add nuw nsw i32 %12, 1
br label %26
20: ; preds = %11
%21 = load i8*, i8** %0
%22 = tail call i64 @is_queen_of_spades(i8* %21)
%23 = icmp eq i64 %22, 0
%24 = add nuw nsw i32 %12, 13
%25 = select i1 %23, i32 %12, i32 %24
br label %26
26: ; preds = %20, %18
%27 = phi i32 [ %19, %18 ], [ %25, %20 ]
%28 = getelementptr inbounds i8*, i8** %0, i64 2
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = tail call i64 @is_hearts(i8 signext %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = add nuw nsw i32 %27, 1
br label %41
35: ; preds = %26
%36 = load i8*, i8** %0
%37 = tail call i64 @is_queen_of_spades(i8* %36)
%38 = icmp eq i64 %37, 0
%39 = add nuw nsw i32 %27, 13
%40 = select i1 %38, i32 %27, i32 %39
br label %41
41: ; preds = %35, %33
%42 = phi i32 [ %34, %33 ], [ %40, %35 ]
%43 = getelementptr inbounds i8*, i8** %0, i64 3
%44 = load i8*, i8** %43
%45 = load i8, i8* %44
%46 = tail call i64 @is_hearts(i8 signext %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %41
%49 = add nuw nsw i32 %42, 1
br label %56
50: ; preds = %41
%51 = load i8*, i8** %0
%52 = tail call i64 @is_queen_of_spades(i8* %51)
%53 = icmp eq i64 %52, 0
%54 = add nuw nsw i32 %42, 13
%55 = select i1 %53, i32 %42, i32 %54
br label %56
56: ; preds = %50, %48
%57 = phi i32 [ %49, %48 ], [ %55, %50 ]
ret i32 %57
}