#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int upTo = 0, count = 0;
  int i, j;
  char found;
  while (upTo < 1 || upTo > 13013) {
    printf("Calculate prime numbers up to [Enter integer]: ");
    scanf("%d", &upTo);
    getchar();
    printf("\n");
  }
  for (i = 2; i < (upTo / 2) + 1; i++) {
    for (j = i / 2; j > 1 && found; j--)
      if (i % j == 0)
        continue;
    printf("prime: %d\n", i);
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x16(%rbp)
jl     1169 <main+0x39>
cmpl   $0x32d5,-0x8(%rbp)
setg   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    1179 <main+0x49>
jmp    11b1 <main+0x81>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114d <main+0x1d>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    125a <main+0x12a>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x1d(%rbp)
jle    1203 <main+0xd3>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1213 <main+0xe3>
jmp    123b <main+0x10b>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    1228 <main+0xf8>
jmp    122d <main+0xfd>
jmp    122d <main+0xfd>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <main+0xb7>
mov    -0x10(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b8 <main+0x88>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea8(%rip),%r14
lea    0xed1(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
lea    -0x32d6(%rax),%ecx
cmp    $0xffffcd2b,%ecx
jb     1170 <main+0x30>
cmp    $0x4,%eax
jb     11e0 <main+0xa0>
mov    $0x1,%ebx
lea    0xe7a(%rip),%r14
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %ecx,%ebx
jl     11c0 <main+0x80>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Calculate prime numbers up to [Enter integer]: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [11 x i8] c"prime: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 13013
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ true, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%18 = call i32 (...) @getchar()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %7
20: ; preds = %13
store i32 2, i32* %4
br label %21
21: ; preds = %52, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = sdiv i32 %23, 2
%25 = add nsw i32 %24, 1
%26 = icmp slt i32 %22, %25
br i1 %26, label %27, label %55
27: ; preds = %21
%28 = load i32, i32* %4
%29 = sdiv i32 %28, 2
store i32 %29, i32* %5
br label %30
30: ; preds = %46, %27
%31 = load i32, i32* %5
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br label %37
37: ; preds = %33, %30
%38 = phi i1 [ false, %30 ], [ %36, %33 ]
br i1 %38, label %39, label %49
39: ; preds = %37
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = srem i32 %40, %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
br label %46
45: ; preds = %39
br label %46
46: ; preds = %45, %44
%47 = load i32, i32* %5
%48 = add nsw i32 %47, -1
store i32 %48, i32* %5
br label %30
49: ; preds = %37
%50 = load i32, i32* %4
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %21
55: ; preds = %21
%56 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [48 x i8] c"Calculate prime numbers up to [Enter integer]: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"prime: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %5
3: ; preds = %5
%4 = icmp ult i32 %10, 4
br i1 %4, label %20, label %13
5: ; preds = %0, %5
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = call i32 (...) @getchar()
%9 = call i32 @putchar(i32 10)
%10 = load i32, i32* %1
%11 = add i32 %10, -13014
%12 = icmp ult i32 %11, -13013
br i1 %12, label %5, label %3
13: ; preds = %3, %13
%14 = phi i32 [ %16, %13 ], [ 2, %3 ]
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i32 %14, 1
%17 = load i32, i32* %1
%18 = sdiv i32 %17, 2
%19 = icmp slt i32 %14, %18
br i1 %19, label %13, label %20
20: ; preds = %13, %3
%21 = call i32 (...) @getchar()
ret i32 0
}