#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 ceil(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sqrt(int);
void Primes(int num) {
  printf("n:%d\n", num);
  int limit = ceil(sqrt(num));
  printf("l:%d\n", limit);
  for (int factor = 2; factor < limit; factor += 1) {
    printf("f: %d\n", factor);
    if ((num % factor) == 0) {
      printf("false\n");
    }
  }
  printf("true\n");
}


x86 assembly (clang, -O0):
<Primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c4 <Primes+0x94>
mov    -0xc(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11b1 <Primes+0x81>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b6 <Primes+0x86>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <Primes+0x46>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Primes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1040 <ceil@plt>
mov    %eax,%ebp
lea    0xe92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%ebp
jl     11c7 <Primes+0x87>
mov    $0x2,%ebx
lea    0xe7e(%rip),%r15
lea    0xe83(%rip),%r12
jmp    11a7 <Primes+0x67>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     11c7 <Primes+0x87>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    11a0 <Primes+0x60>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11a0 <Primes+0x60>
lea    0xe45(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"n:%d\0A\00"
@.str.1 = [6 x i8] c"l:%d\0A\00"
@.str.2 = [7 x i8] c"f: %d\0A\00"
@.str.3 = [7 x i8] c"false\0A\00"
@.str.4 = [6 x i8] c"true\0A\00"
define void @Primes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %2
%8 = call i32 @sqrt(i32 %7)
%9 = call i32 @ceil(i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 2, i32* %4
br label %12
12: ; preds = %26, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %12
29: ; preds = %12
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"n:%d\0A\00"
@.str.1 = [6 x i8] c"l:%d\0A\00"
@.str.2 = [7 x i8] c"f: %d\0A\00"
@str = [5 x i8] c"true\00"
@str.5 = [6 x i8] c"false\00"
define void @Primes(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32 @sqrt(i32 %0)
%4 = tail call i32 @ceil(i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %4, 2
br i1 %6, label %9, label %7
7: ; preds = %16, %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret void
9: ; preds = %1, %16
%10 = phi i32 [ %17, %16 ], [ 2, %1 ]
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = srem i32 %0, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.5, i64 0, i64 0))
br label %16
16: ; preds = %9, %14
%17 = add nuw nsw i32 %10, 1
%18 = icmp eq i32 %17, %4
br i1 %18, label %7, label %9
}