#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 /*<<< orphan*/ UARTprintf(char *, unsigned int const, unsigned int,
                              int /*<<< orphan*/);
unsigned int findNextPrimeNumber(unsigned int);
int /*<<< orphan*/ getPid();
void findNthPrimeNumber(void *num) {
  const unsigned maxCount = (unsigned)num;
  if (maxCount != 0) {
    unsigned prevPrimeNum = 2;
    for (unsigned i = 1; i < maxCount; ++i) {
      prevPrimeNum = findNextPrimeNumber(prevPrimeNum);
      if (prevPrimeNum == 0)
        break;
    }
    UARTprintf("The %uth prime number is: %u. My pid is: %u\n", maxCount,
               prevPrimeNum, getPid());
  }
}


x86 assembly (clang, -O0):
<findNthPrimeNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11bb <findNthPrimeNumber+0x8b>
movl   $0x2,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1194 <findNthPrimeNumber+0x64>
mov    -0x10(%rbp),%edi
call   1050 <findNextPrimeNumber@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1181 <findNthPrimeNumber+0x51>
jmp    1194 <findNthPrimeNumber+0x64>
jmp    1186 <findNthPrimeNumber+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115b <findNthPrimeNumber+0x2b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getPid@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xe4a(%rip),%rdi
call   1030 <UARTprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findNthPrimeNumber>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %r14d,%r14d
je     1164 <findNthPrimeNumber+0x34>
mov    $0x2,%ebp
cmp    $0x1,%r14d
je     116b <findNthPrimeNumber+0x3b>
lea    -0x1(%r14),%ebx
mov    $0x2,%ebp
mov    %ebp,%edi
call   1050 <findNextPrimeNumber@plt>
test   %eax,%eax
je     1169 <findNthPrimeNumber+0x39>
mov    %eax,%ebp
add    $0xffffffff,%ebx
jne    1150 <findNthPrimeNumber+0x20>
jmp    116b <findNthPrimeNumber+0x3b>
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getPid@plt>
lea    0xe87(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <UARTprintf@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"The %uth prime number is: %u. My pid is: %u\0A\00"
define void @findNthPrimeNumber(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %1
store i32 2, i32* %4
store i32 1, i32* %5
br label %11
11: ; preds = %22, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %4
%17 = call i32 @findNextPrimeNumber(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
br label %11
25: ; preds = %20, %11
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 (...) @getPid()
%29 = call i32 @UARTprintf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
br label %30
30: ; preds = %25, %1
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"The %uth prime number is: %u. My pid is: %u\0A\00"
define void @findNthPrimeNumber(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
switch i32 %3, label %6 [
i32 0, label %16
i32 1, label %12
]
4: ; preds = %6
%5 = icmp eq i32 %11, %3
br i1 %5, label %12, label %6
6: ; preds = %1, %4
%7 = phi i32 [ %11, %4 ], [ 1, %1 ]
%8 = phi i32 [ %9, %4 ], [ 2, %1 ]
%9 = tail call i32 @findNextPrimeNumber(i32 %8)
%10 = icmp eq i32 %9, 0
%11 = add nuw i32 %7, 1
br i1 %10, label %12, label %4
12: ; preds = %4, %6, %1
%13 = phi i32 [ 2, %1 ], [ 0, %6 ], [ %9, %4 ]
%14 = tail call i32 (...) @getPid()
%15 = tail call i32 @UARTprintf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %13, i32 %14)
br label %16
16: ; preds = %1, %12
ret void
}