#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int primes(int u) {
  int sum = 0;
  int j, i = 1;
  while (i++ < u) {
    for (j = 2; j <= (i / j); j++) {
      if (!(i % j))
        break;
    }
    if (j > (i / j)) {
      fprintf(stderr, "%d is prime\n", i);
      sum += i;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    -0x4(%rbp),%eax
jge    11c6 <primes+0xb6>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1186 <primes+0x76>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1173 <primes+0x63>
jmp    1186 <primes+0x76>
jmp    1178 <primes+0x68>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <primes+0x34>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jle    11c1 <primes+0xb1>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe4d(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <primes+0x19>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
cmp    $0x2,%edi
jl     118e <primes+0x7e>
mov    %edi,%r14d
xor    %ebp,%ebp
mov    $0x2,%ebx
mov    0x2eb0(%rip),%r12
lea    0xec9(%rip),%r15
jmp    115a <primes+0x4a>
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
add    %ebx,%ebp
lea    0x1(%rbx),%eax
cmp    %r14d,%ebx
mov    %eax,%ebx
je     118e <primes+0x7e>
cmp    $0x4,%ebx
jb     1140 <primes+0x30>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rcx),%esi
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     1150 <primes+0x40>
add    $0x2,%ecx
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %esi,%ecx
cmp    %eax,%esi
jb     1170 <primes+0x60>
jmp    1140 <primes+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"%d is prime\0A\00"
define i32 @primes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %5
br label %6
6: ; preds = %41, %1
%7 = load i32, i32* %5
%8 = add nsw i32 %7, 1
store i32 %8, i32* %5
%9 = load i32, i32* %2
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %42
11: ; preds = %6
store i32 2, i32* %4
br label %12
12: ; preds = %25, %11
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = sdiv i32 %14, %15
%17 = icmp sle i32 %13, %16
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = srem i32 %19, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %18
br label %28
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %12
28: ; preds = %23, %12
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = sdiv i32 %30, %31
%33 = icmp sgt i32 %29, %32
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* %5
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %5
%39 = load i32, i32* %3
%40 = add nsw i32 %39, %38
store i32 %40, i32* %3
br label %41
41: ; preds = %34, %28
br label %6
42: ; preds = %6
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"%d is prime\0A\00"
define i32 @primes(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %23
3: ; preds = %1, %19
%4 = phi i32 [ %21, %19 ], [ 2, %1 ]
%5 = phi i32 [ %20, %19 ], [ 0, %1 ]
%6 = icmp ult i32 %4, 4
br i1 %6, label %15, label %10
7: ; preds = %10
%8 = udiv i32 %4, %14
%9 = icmp ult i32 %11, %8
br i1 %9, label %10, label %15
10: ; preds = %3, %7
%11 = phi i32 [ %14, %7 ], [ 2, %3 ]
%12 = urem i32 %4, %11
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i32 %11, 1
br i1 %13, label %19, label %7
15: ; preds = %7, %3
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%18 = add nsw i32 %4, %5
br label %19
19: ; preds = %10, %15
%20 = phi i32 [ %18, %15 ], [ %5, %10 ]
%21 = add nuw i32 %4, 1
%22 = icmp eq i32 %4, %0
br i1 %22, label %23, label %3
23: ; preds = %19, %1
%24 = phi i32 [ 0, %1 ], [ %20, %19 ]
ret i32 %24
}