#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 tms {
  scalar_t__ tms_stime;
  scalar_t__ tms_utime;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ _SC_CLK_TCK;
int atoi(char const *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(unsigned int);
long sysconf(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
scalar_t__ times(struct tms *);
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    printf("usage: p8a n1 n2\n");
    return EXIT_FAILURE;
  }
  srand((unsigned int)time(NULL));
  int n1 = atoi(argv[1]);
  int n2 = atoi(argv[2]);
  int i = 0;
  while (true) {
    int r = rand() % n1;
    printf("%i - %i\n", i++, r);
    if (r == n2)
      break;
  }
  struct tms t;
  clock_t rt = times(&t);
  long ticksSeg = sysconf(_SC_CLK_TCK);
  printf("Real-time: %f s\n", (double)rt / (double)ticksSeg);
  printf("CPU-time (user): %f s\n", (double)t.tms_utime / (double)ticksSeg);
  printf("CPU-time (proc): %f s\n", (double)t.tms_stime / (double)ticksSeg);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11af <main+0x3f>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ab <main+0x13b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edx
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1221 <main+0xb1>
jmp    1226 <main+0xb6>
jmp    11e6 <main+0x76>
lea    -0x30(%rbp),%rdi
call   1060 <times@plt>
mov    %rax,-0x38(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x40(%rbp)
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdq -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdbf(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvtsi2sdq -0x28(%rbp),%xmm0
cvtsi2sdq -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdb2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdab(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1274 <main+0xf4>
mov    %rsi,%rbp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x8(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
lea    0xe39(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
cltd
idiv   %r15d
mov    %edx,%ebp
lea    0x1(%rbx),%r13d
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%ebx
cmp    %r12d,%ebp
jne    11d0 <main+0x50>
lea    0x8(%rsp),%rdi
call   1070 <times@plt>
mov    %rax,%rbx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
cvtsi2sd %rbx,%xmm0
cvtsi2sd %rax,%xmm1
movsd  %xmm1,(%rsp)
divsd  %xmm1,%xmm0
lea    0xddf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x10(%rsp),%xmm0
divsd  (%rsp),%xmm0
lea    0xdd3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
lea    0xdcd(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2d5e(%rip),%rax
jmp    1287 <main+0x107>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@.str = [18 x i8] c"usage: p8a n1 n2\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"%i - %i\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.2 = [17 x i8] c"Real-time: %f s\0A\00"
@.str.3 = [23 x i8] c"CPU-time (user): %f s\0A\00"
@.str.4 = [23 x i8] c"CPU-time (proc): %f s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.tms
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %68
18: ; preds = %2
%19 = call i64 @time(i32* null)
%20 = trunc i64 %19 to i32
%21 = call i32 @srand(i32 %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
store i32 0, i32* %8
br label %30
30: ; preds = %18, %42
%31 = call i32 (...) @rand()
%32 = load i32, i32* %6
%33 = srem i32 %31, %32
store i32 %33, i32* %9
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
%36 = load i32, i32* %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %36)
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %30
br label %43
42: ; preds = %30
br label %30
43: ; preds = %41
%44 = call i64 @times(%struct.tms* %10)
store i64 %44, i64* %11
%45 = load i32, i32* @_SC_CLK_TCK
%46 = call i64 @sysconf(i32 %45)
store i64 %46, i64* %12
%47 = load i64, i64* %11
%48 = sitofp i64 %47 to double
%49 = load i64, i64* %12
%50 = sitofp i64 %49 to double
%51 = fdiv double %48, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double %51)
%53 = getelementptr inbounds %struct.tms, %struct.tms* %10, i32 0, i32 1
%54 = load i64, i64* %53
%55 = sitofp i64 %54 to double
%56 = load i64, i64* %12
%57 = sitofp i64 %56 to double
%58 = fdiv double %55, %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %58)
%60 = getelementptr inbounds %struct.tms, %struct.tms* %10, i32 0, i32 0
%61 = load i64, i64* %60
%62 = sitofp i64 %61 to double
%63 = load i64, i64* %12
%64 = sitofp i64 %63 to double
%65 = fdiv double %62, %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %65)
%67 = load i32, i32* @EXIT_SUCCESS
store i32 %67, i32* %3
br label %68
68: ; preds = %43, %15
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"%i - %i\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.2 = [17 x i8] c"Real-time: %f s\0A\00"
@.str.3 = [23 x i8] c"CPU-time (user): %f s\0A\00"
@.str.4 = [23 x i8] c"CPU-time (proc): %f s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [17 x i8] c"usage: p8a n1 n2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.tms
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
br label %45
8: ; preds = %2
%9 = tail call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = tail call i32 @srand(i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
br label %18
18: ; preds = %18, %8
%19 = phi i32 [ 0, %8 ], [ %22, %18 ]
%20 = tail call i32 (...) @rand()
%21 = srem i32 %20, %14
%22 = add nuw nsw i32 %19, 1
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21)
%24 = icmp eq i32 %21, %17
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = bitcast %struct.tms* %3 to i8*
%27 = call i64 @times(%struct.tms* %3)
%28 = load i32, i32* @_SC_CLK_TCK
%29 = tail call i64 @sysconf(i32 %28)
%30 = sitofp i64 %27 to double
%31 = sitofp i64 %29 to double
%32 = fdiv double %30, %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 1
%35 = load i64, i64* %34
%36 = sitofp i64 %35 to double
%37 = fdiv double %36, %31
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %37)
%39 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%40 = load i64, i64* %39
%41 = sitofp i64 %40 to double
%42 = fdiv double %41, %31
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %42)
%44 = load i32, i32* @EXIT_SUCCESS
br label %45
45: ; preds = %25, %5
%46 = phi i32 [ %7, %5 ], [ %44, %25 ]
ret i32 %46
}