#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 tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int atoi(char *);
char *malloc(int);
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int main(int argc, char *argv[]) {
  int total_size = 100 * 1024;
  struct timeval pause_time;
  int i;
  char *p;
  int loops_per_sec = 10;
  int duration_secs = 60;
  int loops = duration_secs * loops_per_sec;
  if (argc > 1) {
    total_size = atoi(argv[1]);
  }
  p = malloc(total_size);
  while (loops-- > 0) {
    for (i = 0; i < total_size; ++i) {
      p[i] = i % 128;
    }
    pause_time.tv_sec = 0;
    pause_time.tv_usec = 1000000 / loops_per_sec;
    select(0, NULL, NULL, NULL, &pause_time);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x19000,-0x14(%rbp)
movl   $0xa,-0x3c(%rbp)
movl   $0x3c,-0x40(%rbp)
mov    -0x40(%rbp),%eax
imul   -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x44(%rbp)
cmp    $0x0,%eax
jle    1204 <main+0xd4>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <main+0xa6>
mov    -0x2c(%rbp),%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a6 <main+0x76>
movq   $0x0,-0x20(%rbp)
mov    $0xf4240,%eax
cltd
idivl  -0x3c(%rbp)
mov    %eax,-0x28(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
jmp    118b <main+0x5b>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0xfffffda8,%ebp
lea    0x8(%rsp),%rbx
movq   $0x0,0x10(%rsp)
movl   $0x186a0,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1030 <select@plt>
inc    %ebp
jne    1120 <main+0x10>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 102400, i32* %6
store i32 10, i32* %10
store i32 60, i32* %11
%13 = load i32, i32* %11
%14 = load i32, i32* %10
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %12
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* %6
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %9
br label %26
26: ; preds = %46, %23
%27 = load i32, i32* %12
%28 = add nsw i32 %27, -1
store i32 %28, i32* %12
%29 = icmp sgt i32 %27, 0
br i1 %29, label %30, label %52
30: ; preds = %26
store i32 0, i32* %8
br label %31
31: ; preds = %43, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i32, i32* %8
%37 = srem i32 %36, 128
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %9
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %35
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %31
46: ; preds = %31
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %47
%48 = load i32, i32* %10
%49 = sdiv i32 1000000, %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 %49, i32* %50
%51 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %7)
br label %26
52: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 599, %2 ], [ %10, %7 ]
store i64 0, i64* %5
store i32 100000, i32* %6
%9 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
%10 = add nsw i32 %8, -1
%11 = icmp eq i32 %8, 0
br i1 %11, label %12, label %7
12: ; preds = %7
ret i32 0
}