#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[i]))
      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    11ac <calculate_trick+0x8c>
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    1199 <calculate_trick+0x79>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <is_queen_of_spades@plt>
cmp    $0x0,%rax
je     1194 <calculate_trick+0x74>
mov    -0xc(%rbp),%eax
add    $0xd,%eax
mov    %eax,-0xc(%rbp)
jmp    1199 <calculate_trick+0x79>
jmp    119e <calculate_trick+0x7e>
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    117b <calculate_trick+0x5b>
mov    0x8(%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     1191 <calculate_trick+0x71>
add    $0x1,%ebx
jmp    11a5 <calculate_trick+0x85>
mov    0x10(%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     11bb <calculate_trick+0x9b>
add    $0x1,%ebx
jmp    11cf <calculate_trick+0xaf>
mov    0x18(%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 = %33, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %36
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 %32
20: ; preds = %8
%21 = load i8**, i8*** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i64 @is_queen_of_spades(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 13
store i32 %30, i32* %3
br label %31
31: ; preds = %28, %20
br label %32
32: ; preds = %31, %17
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %5
36: ; preds = %5
%37 = load i32, i32* %3
ret i32 %37
}

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** %13
%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** %28
%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** %43
%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
}