#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 {
  int dummy;
};
typedef long long int64_t;

/* Variables and functions */
char *calc_elapsed_time(struct timeval *, struct timeval *);
int do_some_work(long long);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, long long, char *);
int main(int argc, char **argv) {
  int64_t p;
  for (p = 1; p < 1000000000000ll; p *= 11) {
    struct timeval bef;
    gettimeofday(&bef, 0);
    int res = do_some_work(++p);
    struct timeval aft;
    gettimeofday(&aft, 0);
    printf("%s seconds: %12jd %s prime.\n", calc_elapsed_time(&bef, &aft), p,
           (res == 0) ? "is" : "is not");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movabs $0xe8d4a51000,%rax
cmp    %rax,-0x18(%rbp)
jge    11e2 <main+0xa2>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x18(%rbp)
call   1060 <do_some_work@plt>
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <calc_elapsed_time@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%edi
lea    0xe66(%rip),%rcx
lea    0xe5c(%rip),%rax
cmp    $0x0,%edi
cmove  %rax,%rcx
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
imul   $0xb,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    115e <main+0x1e>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebp
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r12
movabs $0xe8d4a51000,%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x1(%rbp),%rbx
mov    %rbx,%rdi
call   1060 <do_some_work@plt>
mov    %eax,%r13d
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <calc_elapsed_time@plt>
test   %r13d,%r13d
lea    0xe78(%rip),%rcx
lea    0xe6e(%rip),%rdx
cmove  %rdx,%rcx
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
lea    (%rbx,%rbx,4),%rax
lea    0x1(%rbp,%rax,2),%rbp
cmp    %r15,%rbp
jl     1170 <main+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [29 x i8] c"%s seconds: %12jd %s prime.\0A\00"
@.str.1 = [3 x i8] c"is\00"
@.str.2 = [7 x i8] c"is not\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %6
br label %10
10: ; preds = %26, %2
%11 = load i64, i64* %6
%12 = icmp slt i64 %11, 1000000000000
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = call i32 @gettimeofday(%struct.timeval* %7, i32 0)
%15 = load i64, i64* %6
%16 = add nsw i64 %15, 1
store i64 %16, i64* %6
%17 = call i32 @do_some_work(i64 %16)
store i32 %17, i32* %8
%18 = call i32 @gettimeofday(%struct.timeval* %9, i32 0)
%19 = call i8* @calc_elapsed_time(%struct.timeval* %7, %struct.timeval* %9)
%20 = load i64, i64* %6
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%25 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %19, i64 %20, i8* %24)
br label %26
26: ; preds = %13
%27 = load i64, i64* %6
%28 = mul nsw i64 %27, 11
store i64 %28, i64* %6
br label %10
29: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [29 x i8] c"%s seconds: %12jd %s prime.\0A\00"
@.str.1 = [3 x i8] c"is\00"
@.str.2 = [7 x i8] c"is not\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ 1, %2 ], [ %17, %7 ]
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%10 = add nsw i64 %8, 1
%11 = call i32 @do_some_work(i64 %10)
%12 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%13 = call i8* @calc_elapsed_time(%struct.timeval* %3, %struct.timeval* %4)
%14 = icmp eq i32 %11, 0
%15 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13, i64 %10, i8* %15)
%17 = mul nsw i64 %10, 11
%18 = icmp slt i64 %17, 1000000000000
br i1 %18, label %7, label %19
19: ; preds = %7
ret i32 0
}