#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 is_prime(int);
int /*<<< orphan*/ printf(char *, ...);
void print_primes_upto_n(int n) {
  int i;
  for (i = 2; i <= n; i++) {
    if (is_prime(i) == 1) {
      printf("%d\t", i);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_primes_upto_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1173 <print_primes_upto_n+0x53>
mov    -0x8(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x1,%eax
jne    1160 <print_primes_upto_n+0x40>
mov    -0x8(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1165 <print_primes_upto_n+0x45>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <print_primes_upto_n+0x12>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_primes_upto_n>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jge    1149 <print_primes_upto_n+0x19>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    %edi,%r15d
neg    %r15d
mov    $0x2,%ebx
lea    0xea5(%rip),%r14
jmp    1173 <print_primes_upto_n+0x43>
nopl   (%rax)
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     113a <print_primes_upto_n+0xa>
mov    %ebx,%edi
call   1050 <is_prime@plt>
cmp    $0x1,%eax
jne    1160 <print_primes_upto_n+0x30>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <print_primes_upto_n+0x30>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_primes_upto_n(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 2, i32* %3
br label %4
4: ; preds = %16, %1
%5 = load i32, i32* %3
%6 = load i32, i32* %2
%7 = icmp sle i32 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = load i32, i32* %3
%10 = call i32 @is_prime(i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %8
br label %16
16: ; preds = %15
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %4
19: ; preds = %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\09\00"
define void @print_primes_upto_n(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %12, label %3
3: ; preds = %1, %9
%4 = phi i32 [ %10, %9 ], [ 2, %1 ]
%5 = tail call i32 @is_prime(i32 %4)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %9
9: ; preds = %3, %7
%10 = add nuw i32 %4, 1
%11 = icmp eq i32 %4, %0
br i1 %11, label %12, label %3
12: ; preds = %9, %1
%13 = tail call i32 @putchar(i32 10)
ret void
}