int main(void) {
  int p, d;
  _Bool isPrime;
  for (p = 2; p <= 50; ++p) {
    isPrime = 1;
    for (d = 2; d < p; ++d) {
      if (p % d == 0)
        isPrime = 0;
      if (isPrime != 0)
        printf("%i ", p);
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
cmpl   $0x32,-0x8(%rbp)
jg     11a3 <main+0x93>
movb   $0x1,-0xd(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1190 <main+0x80>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    115b <main+0x4b>
movb   $0x0,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
je     117d <main+0x6d>
mov    -0x8(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <main+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <main+0x2b>
jmp    1195 <main+0x85>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <main+0x16>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x2,%r12d
lea    0xecb(%rip),%r14
xor    %r15d,%r15d
jmp    114e <main+0x2e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
add    $0xffffffff,%r15d
cmp    $0x33,%r12d
je     1198 <main+0x78>
cmp    $0x3,%r12d
jb     1140 <main+0x20>
mov    $0x2,%ebx
mov    $0x1,%bpl
jmp    1173 <main+0x53>
xchg   %ax,%ax
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x2,%eax
je     1140 <main+0x20>
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
movzbl %bpl,%ebp
cmove  %edx,%ebp
test   $0x1,%bpl
je     1160 <main+0x40>
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%i \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i32 2, i32* %2
br label %5
5: ; preds = %32, %0
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 50
br i1 %7, label %8, label %35
8: ; preds = %5
store i8 1, i8* %4
store i32 2, i32* %3
br label %9
9: ; preds = %28, %8
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = srem i32 %14, %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i8 0, i8* %4
br label %19
19: ; preds = %18, %13
%20 = load i8, i8* %4
%21 = trunc i8 %20 to i1
%22 = zext i1 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %19
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %9
31: ; preds = %9
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %5
35: ; preds = %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%i \00"
define i32 @main() {
br label %1
1: ; preds = %0, %17
%2 = phi i32 [ 2, %0 ], [ %18, %17 ]
%3 = icmp ugt i32 %2, 2
br i1 %3, label %4, label %17
4: ; preds = %1, %14
%5 = phi i8 [ %9, %14 ], [ 1, %1 ]
%6 = phi i32 [ %15, %14 ], [ 2, %1 ]
%7 = urem i32 %2, %6
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8 0, i8 %5
%10 = and i8 %9, 1
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %14
14: ; preds = %4, %12
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %4
17: ; preds = %14, %1
%18 = add nuw nsw i32 %2, 1
%19 = icmp eq i32 %18, 51
br i1 %19, label %20, label %1
20: ; preds = %17
%21 = tail call i32 @putchar(i32 10)
ret i32 0
}