#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*/ printf(char *, ...);
void primes(int cap) {
  int i, j, composite;
  for (i = 2; i < cap; ++i) {
    composite = 0;
    for (j = 2; j * j < i; ++j) {
      composite += !(i % j);
    }
    if (!composite) {
      printf("%d\t", i);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a2 <primes+0x92>
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1174 <primes+0x64>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113c <primes+0x2c>
cmpl   $0x0,-0x10(%rbp)
jne    118f <primes+0x7f>
mov    -0x8(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1194 <primes+0x84>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <primes+0x12>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primes>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jl     1181 <primes+0x61>
mov    %edi,%ebx
mov    $0x2,%ebp
lea    0xec9(%rip),%r14
jmp    1153 <primes+0x33>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
je     1181 <primes+0x61>
cmp    $0x5,%ebp
jb     1140 <primes+0x20>
xor    %ecx,%ecx
mov    $0x3,%esi
nop
lea    -0x1(%rsi),%edi
mov    %ebp,%eax
xor    %edx,%edx
div    %edi
cmp    $0x1,%edx
adc    $0x0,%ecx
mov    %esi,%eax
imul   %esi,%eax
add    $0x1,%esi
cmp    %ebp,%eax
jb     1160 <primes+0x40>
test   %ecx,%ecx
jne    114c <primes+0x2c>
jmp    1140 <primes+0x20>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @primes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 2, i32* %3
br label %6
6: ; preds = %36, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %39
10: ; preds = %6
store i32 0, i32* %5
store i32 2, i32* %4
br label %11
11: ; preds = %26, %10
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = mul nsw i32 %12, %13
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = srem i32 %18, %19
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
%23 = zext i1 %22 to i32
%24 = load i32, i32* %5
%25 = add nsw i32 %24, %23
store i32 %25, i32* %5
br label %26
26: ; preds = %17
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %11
29: ; preds = %11
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %6
39: ; preds = %6
%40 = 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 @primes(i32 %0) {
%2 = icmp sgt i32 %0, 2
br i1 %2, label %3, label %23
3: ; preds = %1, %20
%4 = phi i32 [ %21, %20 ], [ 2, %1 ]
%5 = icmp ugt i32 %4, 4
br i1 %5, label %6, label %18
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ 0, %3 ]
%8 = phi i32 [ %13, %6 ], [ 2, %3 ]
%9 = urem i32 %4, %8
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %7, %11
%13 = add nuw nsw i32 %8, 1
%14 = mul nsw i32 %13, %13
%15 = icmp ult i32 %14, %4
br i1 %15, label %6, label %16
16: ; preds = %6
%17 = icmp eq i32 %12, 0
br i1 %17, label %18, label %20
18: ; preds = %3, %16
%19 = 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 %20
20: ; preds = %16, %18
%21 = add nuw nsw i32 %4, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %3
23: ; preds = %20, %1
%24 = tail call i32 @putchar(i32 10)
ret void
}