#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int divisionwithmodule(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ isPrime(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  int i, maxrep = 0, maxnumber = 0, aux;
  for (i = 2; i < 1000; i++) {
    if (isPrime(i)) {
      aux = divisionwithmodule(1, i);
      if (aux > maxrep) {
        maxrep = aux;
        maxnumber = i;
      }
    }
  }
  printf("maxnumber = %d with reps = %d", maxnumber, maxrep);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11d0 <main+0x90>
mov    -0x1c(%rbp),%edi
call   1050 <isPrime@plt>
cmp    $0x0,%rax
je     11bd <main+0x7d>
mov    -0x1c(%rbp),%esi
mov    $0x1,%edi
call   1060 <divisionwithmodule@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11b8 <main+0x78>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11bd <main+0x7d>
jmp    11c2 <main+0x82>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <main+0x31>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x2,%ebx
xor    %ebp,%ebp
jmp    116b <main+0x2b>
xchg   %ax,%ax
add    $0x1,%ebx
cmp    $0x3e8,%ebx
je     118e <main+0x4e>
mov    %ebx,%edi
call   1050 <isPrime@plt>
test   %rax,%rax
je     1160 <main+0x20>
mov    $0x1,%edi
mov    %ebx,%esi
call   1060 <divisionwithmodule@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
cmovg  %ebx,%r14d
jmp    1160 <main+0x20>
lea    0xe6b(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%esi
sub    (%rsp),%esi
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [30 x i8] c"maxnumber = %d with reps = %d\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i32 0, i32* %5
store i32 0, i32* %6
store i32 2, i32* %4
br label %9
9: ; preds = %27, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i32, i32* %4
%14 = call i64 @isPrime(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @divisionwithmodule(i32 1, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %7
store i32 %23, i32* %5
%24 = load i32, i32* %4
store i32 %24, i32* %6
br label %25
25: ; preds = %22, %16
br label %26
26: ; preds = %25, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %9
30: ; preds = %9
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32)
%34 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%38 = load i64, i64* %37
%39 = sub nsw i64 %36, %38
%40 = trunc i64 %39 to i32
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [30 x i8] c"maxnumber = %d with reps = %d\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %17
%7 = phi i32 [ 2, %0 ], [ %20, %17 ]
%8 = phi i32 [ 0, %0 ], [ %19, %17 ]
%9 = phi i32 [ 0, %0 ], [ %18, %17 ]
%10 = tail call i64 @isPrime(i32 %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = tail call i32 @divisionwithmodule(i32 1, i32 %7)
%14 = icmp sgt i32 %13, %9
%15 = select i1 %14, i32 %13, i32 %9
%16 = select i1 %14, i32 %7, i32 %8
br label %17
17: ; preds = %12, %6
%18 = phi i32 [ %9, %6 ], [ %15, %12 ]
%19 = phi i32 [ %8, %6 ], [ %16, %12 ]
%20 = add nuw nsw i32 %7, 1
%21 = icmp eq i32 %20, 1000
br i1 %21, label %22, label %6
22: ; preds = %17
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %18)
%24 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%28 = load i64, i64* %27
%29 = sub nsw i64 %26, %28
%30 = trunc i64 %29 to i32
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %30)
ret i32 0
}