#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 findNextPrimeNumber(unsigned int);
void findPrimeNumbers(void *amount) {
  const unsigned maxCount = (unsigned)amount;
  if (maxCount != 0) {
    UARTprintf("2");
    unsigned prevPrimeNum = 2;
    for (unsigned i = 1; i <= maxCount; ++i) {
      prevPrimeNum = findNextPrimeNumber(prevPrimeNum);
      if (prevPrimeNum == 0)
        break;
      UARTprintf(", %u", prevPrimeNum);
    }
    UARTprintf(".\r\nDone!\r\n");
  }
}


x86 assembly (clang, -O0):
<findPrimeNumbers>:
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     11ac <findPrimeNumbers+0x8c>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <UARTprintf@plt>
movl   $0x2,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     119e <findPrimeNumbers+0x7e>
mov    -0x10(%rbp),%edi
call   1040 <findNextPrimeNumber@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    117f <findPrimeNumbers+0x5f>
jmp    119e <findPrimeNumbers+0x7e>
mov    -0x10(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <UARTprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <findPrimeNumbers+0x39>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <UARTprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPrimeNumbers>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
test   %r15d,%r15d
je     1189 <findPrimeNumbers+0x69>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <UARTprintf@plt>
mov    $0x2,%ebp
mov    $0x1,%ebx
lea    0xeb4(%rip),%r14
xchg   %ax,%ax
mov    %ebp,%edi
call   1040 <findNextPrimeNumber@plt>
test   %eax,%eax
je     1171 <findPrimeNumbers+0x51>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <UARTprintf@plt>
add    $0x1,%ebx
cmp    %r15d,%ebx
jbe    1150 <findPrimeNumbers+0x30>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <UARTprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"2\00"
@.str.1 = [5 x i8] c", %u\00"
@.str.2 = [11 x i8] c".\0D\0ADone!\0D\0A\00"
define void @findPrimeNumbers(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
%11 = call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %4
store i32 1, i32* %5
br label %12
12: ; preds = %25, %10
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = icmp ule i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @findNextPrimeNumber(i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %28
22: ; preds = %16
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %12
28: ; preds = %21, %12
%29 = call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"2\00"
@.str.1 = [5 x i8] c", %u\00"
@.str.2 = [11 x i8] c".\0D\0ADone!\0D\0A\00"
define void @findPrimeNumbers(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = icmp eq i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %12
%8 = phi i32 [ %14, %12 ], [ 1, %5 ]
%9 = phi i32 [ %10, %12 ], [ 2, %5 ]
%10 = tail call i32 @findNextPrimeNumber(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%14 = add i32 %8, 1
%15 = icmp ugt i32 %14, %3
br i1 %15, label %16, label %7
16: ; preds = %12, %7
%17 = tail call i32 (i8*, ...) @UARTprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
ret void
}