#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 */
typedef int /*<<< orphan*/ cBuf;

/* Variables and functions */
char *calloc(unsigned int, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stdin;
int main(void) {
  unsigned int i = 0;
  unsigned int j = 0;
  unsigned int uiLimit = 0;
  unsigned int uiPrime = 0;
  char cBuf[64];
  char *cpTable;
  printf("Maximum number:");
  fgets(cBuf, sizeof(cBuf) / sizeof(cBuf[0]), stdin);
  sscanf(cBuf, "%u", &uiLimit);
  cpTable = calloc(uiLimit, sizeof(char));
  for (i = 1; i < uiLimit; i++) {
    if (cpTable[i] == 1) {
      continue;
    }
    uiPrime++;
    for (j = i + i + 1; j < uiLimit; j = j + i + 1) {
      cpTable[j] = 1;
    }
  }
  for (i = 1; i < uiLimit; i++) {
    if (cpTable[i] == 0) {
      printf("%u\n", i + 1);
    }
  }
  free(cpTable);
  printf("The number of primes under %u = [%u]\n", uiLimit, uiPrime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1050 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x68(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1241 <main+0xf1>
mov    -0x68(%rbp),%rax
mov    -0x8(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1,%eax
jne    11f1 <main+0xa1>
jmp    1233 <main+0xe3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    122e <main+0xde>
mov    -0x68(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x1,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1206 <main+0xb6>
jmp    1233 <main+0xe3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11cc <main+0x7c>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    128f <main+0x13f>
mov    -0x68(%rbp),%rax
mov    -0x8(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    127c <main+0x12c>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1281 <main+0x131>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1248 <main+0xf8>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe95(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
lea    0xe79(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
cmp    $0x2,%rbx
jb     1268 <main+0x118>
xor    %r14d,%r14d
mov    $0x1,%eax
mov    $0x3,%ecx
mov    $0x2,%edx
jmp    11ef <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rax
add    $0x2,%ecx
add    $0x1,%edx
cmp    %rbx,%rax
je     121f <main+0xcf>
cmpb   $0x1,0x0(%rbp,%rax,1)
je     11e0 <main+0x90>
add    $0x1,%r14d
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
cmp    %ebx,%esi
jae    11e0 <main+0x90>
mov    %ecx,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %esi,%edi
movb   $0x1,0x0(%rbp,%rdi,1)
add    %edx,%esi
cmp    %ebx,%esi
jb     1210 <main+0xc0>
jmp    11e0 <main+0x90>
cmp    $0x2,%ebx
jb     1268 <main+0x118>
mov    $0x1,%esi
lea    0xde3(%rip),%r15
jmp    124a <main+0xfa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
mov    %r12,%rsi
cmp    %rax,%r12
jae    1268 <main+0x118>
lea    0x1(%rsi),%r12
cmpb   $0x0,0x0(%rbp,%rsi,1)
jne    1240 <main+0xf0>
add    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%ebx
jmp    1240 <main+0xf0>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xda0(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Maximum number:\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [38 x i8] c"The number of primes under %u = [%u]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 64, i32 %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%14 = load i32, i32* %4
%15 = call i8* @calloc(i32 %14, i32 1)
store i8* %15, i8** %7
store i32 1, i32* %2
br label %16
16: ; preds = %51, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %54
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i32, i32* %2
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %20
br label %51
29: ; preds = %20
%30 = load i32, i32* %5
%31 = add i32 %30, 1
store i32 %31, i32* %5
%32 = load i32, i32* %2
%33 = load i32, i32* %2
%34 = add i32 %32, %33
%35 = add i32 %34, 1
store i32 %35, i32* %3
br label %36
36: ; preds = %45, %29
%37 = load i32, i32* %3
%38 = load i32, i32* %4
%39 = icmp ult i32 %37, %38
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i8*, i8** %7
%42 = load i32, i32* %3
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 1, i8* %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %3
%47 = load i32, i32* %2
%48 = add i32 %46, %47
%49 = add i32 %48, 1
store i32 %49, i32* %3
br label %36
50: ; preds = %36
br label %51
51: ; preds = %50, %28
%52 = load i32, i32* %2
%53 = add i32 %52, 1
store i32 %53, i32* %2
br label %16
54: ; preds = %16
store i32 1, i32* %2
br label %55
55: ; preds = %72, %54
%56 = load i32, i32* %2
%57 = load i32, i32* %4
%58 = icmp ult i32 %56, %57
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = load i8*, i8** %7
%61 = load i32, i32* %2
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %59
%68 = load i32, i32* %2
%69 = add i32 %68, 1
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %67, %59
br label %72
72: ; preds = %71
%73 = load i32, i32* %2
%74 = add i32 %73, 1
store i32 %74, i32* %2
br label %55
75: ; preds = %55
%76 = load i8*, i8** %7
%77 = call i32 @free(i8* %76)
%78 = load i32, i32* %4
%79 = load i32, i32* %5
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %78, i32 %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Maximum number:\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [38 x i8] c"The number of primes under %u = [%u]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 64, i32 %6)
%8 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = call i8* @calloc(i32 %9, i32 1)
%11 = icmp ugt i32 %9, 1
br i1 %11, label %12, label %55
12: ; preds = %0
%13 = zext i32 %9 to i64
br label %15
14: ; preds = %36
br i1 %11, label %40, label %55
15: ; preds = %12, %36
%16 = phi i64 [ 1, %12 ], [ %38, %36 ]
%17 = phi i32 [ 0, %12 ], [ %37, %36 ]
%18 = getelementptr inbounds i8, i8* %10, i64 %16
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 1
br i1 %20, label %36, label %21
21: ; preds = %15
%22 = add i32 %17, 1
%23 = trunc i64 %16 to i32
%24 = shl i32 %23, 1
%25 = or i32 %24, 1
%26 = icmp ult i32 %25, %9
br i1 %26, label %27, label %36
27: ; preds = %21
%28 = trunc i64 %16 to i32
%29 = add i32 %28, 1
br label %30
30: ; preds = %27, %30
%31 = phi i32 [ %25, %27 ], [ %34, %30 ]
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %10, i64 %32
store i8 1, i8* %33
%34 = add i32 %29, %31
%35 = icmp ult i32 %34, %9
br i1 %35, label %30, label %36
36: ; preds = %30, %21, %15
%37 = phi i32 [ %17, %15 ], [ %22, %21 ], [ %22, %30 ]
%38 = add nuw nsw i64 %16, 1
%39 = icmp eq i64 %38, %13
br i1 %39, label %14, label %15
40: ; preds = %14, %51
%41 = phi i32 [ %52, %51 ], [ %9, %14 ]
%42 = phi i64 [ %46, %51 ], [ 1, %14 ]
%43 = getelementptr inbounds i8, i8* %10, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
%46 = add nuw nsw i64 %42, 1
br i1 %45, label %47, label %51
47: ; preds = %40
%48 = trunc i64 %46 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %1
br label %51
51: ; preds = %40, %47
%52 = phi i32 [ %50, %47 ], [ %41, %40 ]
%53 = zext i32 %52 to i64
%54 = icmp ult i64 %46, %53
br i1 %54, label %40, label %55
55: ; preds = %51, %0, %14
%56 = phi i32 [ %37, %14 ], [ 0, %0 ], [ %37, %51 ]
%57 = phi i32 [ %9, %14 ], [ %9, %0 ], [ %52, %51 ]
%58 = call i32 @free(i8* %10)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %57, i32 %56)
ret i32 0
}