#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_sec;
  int tv_usec;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ _IOLBF;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, int, int /*<<< orphan*/);
scalar_t__ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: loadtestend $hz | plug -i /path/to/lbus\n");
    exit(1);
  }
  int hz = atoi(argv[1]);
  int pid = getpid();
  if (setvbuf(stdout, NULL, _IOLBF, 0))
    fprintf(stderr, "Failed to make stdout line-buffered.");
  int i = 0;
  for (;;) {
    struct timeval tv = {0, 0};
    gettimeofday(&tv, NULL);
    int s = tv.tv_sec;
    int u = tv.tv_usec;
    printf("pid:%d timestamp_s:%d.%06d seqno:%d\n", pid, s, u, i++);
    usleep(1E6 / hz);
  }
  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)
cmpl   $0x2,-0x8(%rbp)
jge    11cf <main+0x3f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1080 <setvbuf@plt>
cmp    $0x0,%rax
je     1225 <main+0x95>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    %r8d,%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    %eax,-0x1c(%rbp)
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xd79(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si %xmm0,%edi
call   10b0 <usleep@plt>
jmp    122c <main+0x9c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    1247 <main+0xc7>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
test   %rax,%rax
je     11e4 <main+0x64>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1060 <fprintf@plt>
cvtsi2sd %r14d,%xmm0
movsd  0xe0f(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r13d
mov    %rsp,%r14
lea    0xe71(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0x1(%rbx),%ebp
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%r8d
call   1040 <printf@plt>
mov    %r13d,%edi
call   10a0 <usleep@plt>
mov    %ebp,%ebx
jmp    1210 <main+0x90>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [48 x i8] c"Usage: loadtestend $hz | plug -i /path/to/lbus\0A\00"
@stdout = global i32 0
@_IOLBF = global i32 0
@.str.1 = [37 x i8] c"Failed to make stdout line-buffered.\00"
@.str.2 = [37 x i8] c"pid:%d timestamp_s:%d.%06d seqno:%d\0A\00"
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 %struct.timeval
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
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
%23 = call i32 (...) @getpid()
store i32 %23, i32* %7
%24 = load i32, i32* @stdout
%25 = load i32, i32* @_IOLBF
%26 = call i64 @setvbuf(i32 %24, i32* null, i32 %25, i32 0)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %28, %18
store i32 0, i32* %8
br label %32
32: ; preds = %32, %31
%33 = bitcast %struct.timeval* %9 to i8*
%34 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %10
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%38 = load i32, i32* %37
store i32 %38, i32* %11
%39 = load i32, i32* %7
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
%44 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %40, i32 %41, i32 %42)
%45 = load i32, i32* %6
%46 = sitofp i32 %45 to double
%47 = fdiv double 1.000000e+06, %46
%48 = fptosi double %47 to i32
%49 = call i32 @usleep(i32 %48)
br label %32
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [48 x i8] c"Usage: loadtestend $hz | plug -i /path/to/lbus\0A\00"
@stdout = global i32 0
@_IOLBF = global i32 0
@.str.1 = [37 x i8] c"Failed to make stdout line-buffered.\00"
@.str.2 = [37 x i8] c"pid:%d timestamp_s:%d.%06d seqno:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 (...) @getpid()
%14 = load i32, i32* @stdout
%15 = load i32, i32* @_IOLBF
%16 = tail call i64 @setvbuf(i32 %14, i32* null, i32 %15, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %9
%22 = bitcast %struct.timeval* %3 to i8*
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%25 = sitofp i32 %12 to double
%26 = fdiv double 1.000000e+06, %25
%27 = fptosi double %26 to i32
br label %28
28: ; preds = %28, %21
%29 = phi i32 [ 0, %21 ], [ %33, %28 ]
%30 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%31 = load i32, i32* %23
%32 = load i32, i32* %24
%33 = add nuw nsw i32 %29, 1
%34 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %31, i32 %32, i32 %29)
%35 = tail call i32 @usleep(i32 %27)
br label %28
}