#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 timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int EXIT_SUCCESS;
int get_usr_input(char *, int *);
char interpret_command(char *, long double *);
double mem_worker(long, long, struct timespec *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char input[256];
  char *buff = &input[0];
  int bytes_so_far = 0;
  long bytes = 0;
  int delay_us = 1000000.0;
  char cmd_type;
  long double cmd_data;
  double retval;
  int rcvd = 0;
  int running = 1;
  struct timespec tv_start, tv_stop;
  struct timespec delay;
  struct timespec const_delay;
  double t_start, t_stop;
  int num_iter = 100000;
  long touch_bytes = 0;
  long counter = 0;
  delay.tv_sec = 0;
  delay.tv_nsec = 100000000;
  const_delay.tv_sec = 0;
  const_delay.tv_nsec = 10000000;
  setbuf(stdin, NULL);
  while (running == 1) {
    retval = mem_worker(bytes, touch_bytes, &const_delay);
    rcvd = get_usr_input(buff, &bytes_so_far);
    if (rcvd == 1) {
      cmd_type = interpret_command(buff, &cmd_data);
      switch (cmd_type) {
      case ('m'):
        bytes = (long)cmd_data;
        break;
      case ('d'):
        delay.tv_sec = (int)(cmd_data / 1000000000);
        delay.tv_nsec =
            (long)((cmd_data / 1000000000 - delay.tv_sec) * 1000000000);
        break;
      case ('i'):
        num_iter = (int)cmd_data;
        break;
      case ('t'):
        touch_bytes = (long)cmd_data;
        break;
      case ('q'):
        running = 0;
        break;
      default:
        break;
      }
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
movq   $0x0,-0x128(%rbp)
movl   $0xf4240,-0x12c(%rbp)
movl   $0x0,-0x14c(%rbp)
movl   $0x1,-0x150(%rbp)
movl   $0x186a0,-0x184(%rbp)
movq   $0x0,-0x190(%rbp)
movq   $0x0,-0x198(%rbp)
movl   $0x0,-0x168(%rbp)
movl   $0x5f5e100,-0x164(%rbp)
e1 f5 05
movl   $0x0,-0x170(%rbp)
movl   $0x989680,-0x16c(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
cmpl   $0x1,-0x150(%rbp)
jne    141f <main+0x2df>
mov    -0x128(%rbp),%rdi
mov    -0x190(%rbp),%rsi
lea    -0x170(%rbp),%rdx
call   1050 <mem_worker@plt>
movsd  %xmm0,-0x148(%rbp)
ff
mov    -0x118(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
call   1060 <get_usr_input@plt>
mov    %eax,-0x14c(%rbp)
cmpl   $0x1,-0x14c(%rbp)
jne    141a <main+0x2da>
mov    -0x118(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   1040 <interpret_command@plt>
mov    %al,-0x12d(%rbp)
movsbl -0x12d(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x1e0(%rbp)
sub    $0x10,%eax
ja     1410 <main+0x2d0>
mov    -0x1e0(%rbp),%rax
lea    0xd78(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
fldt   -0x140(%rbp)
fnstcw -0x1c2(%rbp)
movzwl -0x1c2(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1c4(%rbp)
fldcw  -0x1c4(%rbp)
fistpll -0x1c0(%rbp)
fldcw  -0x1c2(%rbp)
mov    -0x1c0(%rbp),%rax
mov    %rax,-0x128(%rbp)
jmp    1415 <main+0x2d5>
fldt   -0x140(%rbp)
flds   0xd1b(%rip)
fdivr  %st,%st(1)
fnstcw -0x1c6(%rbp)
movzwl -0x1c6(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1c8(%rbp)
fldcw  -0x1c8(%rbp)
fxch   %st(1)
fistpl -0x1b8(%rbp)
fldcw  -0x1c6(%rbp)
mov    -0x1b8(%rbp),%eax
mov    %eax,-0x168(%rbp)
fldt   -0x140(%rbp)
fdiv   %st(1),%st
mov    -0x168(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
fildl  -0x1b4(%rbp)
fsubrp %st,%st(1)
fmulp  %st,%st(1)
fnstcw -0x1ca(%rbp)
movzwl -0x1ca(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1cc(%rbp)
fldcw  -0x1cc(%rbp)
fistpll -0x1b0(%rbp)
fldcw  -0x1ca(%rbp)
mov    -0x1b0(%rbp),%rax
mov    %eax,-0x164(%rbp)
jmp    1415 <main+0x2d5>
fldt   -0x140(%rbp)
fnstcw -0x1ce(%rbp)
movzwl -0x1ce(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1d0(%rbp)
fldcw  -0x1d0(%rbp)
fistpl -0x1a4(%rbp)
fldcw  -0x1ce(%rbp)
mov    -0x1a4(%rbp),%eax
mov    %eax,-0x184(%rbp)
jmp    1415 <main+0x2d5>
fldt   -0x140(%rbp)
fnstcw -0x1d2(%rbp)
movzwl -0x1d2(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1d4(%rbp)
fldcw  -0x1d4(%rbp)
fistpll -0x1a0(%rbp)
fldcw  -0x1d2(%rbp)
mov    -0x1a0(%rbp),%rax
mov    %rax,-0x190(%rbp)
jmp    1415 <main+0x2d5>
movl   $0x0,-0x150(%rbp)
jmp    1415 <main+0x2d5>
jmp    1415 <main+0x2d5>
jmp    141a <main+0x2da>
jmp    11f4 <main+0xb4>
mov    0x2bb2(%rip),%rax
mov    (%rax),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
movl   $0x0,0x14(%rsp)
movabs $0x98968000000000,%rax
mov    %rax,0x28(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <setbuf@plt>
lea    0x28(%rsp),%r14
lea    0x40(%rsp),%r13
lea    0x14(%rsp),%r15
lea    0x30(%rsp),%r12
xor    %ebp,%ebp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <mem_worker@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <get_usr_input@plt>
cmp    $0x1,%eax
jne    1190 <main+0x50>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <interpret_command@plt>
movsbl %al,%eax
cmp    $0x74,%eax
je     11f5 <main+0xb5>
cmp    $0x71,%eax
je     1222 <main+0xe2>
cmp    $0x6d,%eax
jne    1190 <main+0x50>
fldt   0x30(%rsp)
fnstcw 0xe(%rsp)
movzwl 0xe(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x12(%rsp)
fldcw  0x12(%rsp)
fistpll 0x18(%rsp)
fldcw  0xe(%rsp)
mov    0x18(%rsp),%rbp
jmp    1190 <main+0x50>
fldt   0x30(%rsp)
fnstcw 0xc(%rsp)
movzwl 0xc(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x10(%rsp)
fldcw  0x10(%rsp)
fistpll 0x20(%rsp)
fldcw  0xc(%rsp)
mov    0x20(%rsp),%rbx
jmp    1190 <main+0x50>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8
%12 = alloca x86_fp80
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timespec
%17 = alloca %struct.timespec
%18 = alloca %struct.timespec
%19 = alloca %struct.timespec
%20 = alloca double
%21 = alloca double
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8* %25, i8** %7
store i32 0, i32* %8
store i64 0, i64* %9
store i32 1000000, i32* %10
store i32 0, i32* %14
store i32 1, i32* %15
store i32 100000, i32* %22
store i64 0, i64* %23
store i64 0, i64* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
store i32 0, i32* %26
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 1
store i32 100000000, i32* %27
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
store i32 0, i32* %28
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
store i32 10000000, i32* %29
%30 = load i32, i32* @stdin
%31 = call i32 @setbuf(i32 %30, i32* null)
br label %32
32: ; preds = %75, %2
%33 = load i32, i32* %15
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %76
35: ; preds = %32
%36 = load i64, i64* %9
%37 = load i64, i64* %23
%38 = call double @mem_worker(i64 %36, i64 %37, %struct.timespec* %19)
store double %38, double* %13
%39 = load i8*, i8** %7
%40 = call i32 @get_usr_input(i8* %39, i32* %8)
store i32 %40, i32* %14
%41 = load i32, i32* %14
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %75
43: ; preds = %35
%44 = load i8*, i8** %7
%45 = call signext i8 @interpret_command(i8* %44, x86_fp80* %12)
store i8 %45, i8* %11
%46 = load i8, i8* %11
%47 = sext i8 %46 to i32
switch i32 %47, label %73 [
i32 109, label %48
i32 100, label %51
i32 105, label %66
i32 116, label %69
i32 113, label %72
]
48: ; preds = %43
%49 = load x86_fp80, x86_fp80* %12
%50 = fptosi x86_fp80 %49 to i64
store i64 %50, i64* %9
br label %74
51: ; preds = %43
%52 = load x86_fp80, x86_fp80* %12
%53 = fdiv x86_fp80 %52, 0xK401CEE6B280000000000
%54 = fptosi x86_fp80 %53 to i32
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
store i32 %54, i32* %55
%56 = load x86_fp80, x86_fp80* %12
%57 = fdiv x86_fp80 %56, 0xK401CEE6B280000000000
%58 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
%59 = load i32, i32* %58
%60 = sitofp i32 %59 to x86_fp80
%61 = fsub x86_fp80 %57, %60
%62 = fmul x86_fp80 %61, 0xK401CEE6B280000000000
%63 = fptosi x86_fp80 %62 to i64
%64 = trunc i64 %63 to i32
%65 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 1
store i32 %64, i32* %65
br label %74
66: ; preds = %43
%67 = load x86_fp80, x86_fp80* %12
%68 = fptosi x86_fp80 %67 to i32
store i32 %68, i32* %22
br label %74
69: ; preds = %43
%70 = load x86_fp80, x86_fp80* %12
%71 = fptosi x86_fp80 %70 to i64
store i64 %71, i64* %23
br label %74
72: ; preds = %43
store i32 0, i32* %15
br label %74
73: ; preds = %43
br label %74
74: ; preds = %73, %72, %69, %66, %51, %48
br label %75
75: ; preds = %74, %35
br label %32
76: ; preds = %32
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca x86_fp80
%6 = alloca %struct.timespec
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast x86_fp80* %5 to i8*
%10 = bitcast %struct.timespec* %6 to i8*
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
store i32 10000000, i32* %12
%13 = load i32, i32* @stdin
%14 = tail call i32 @setbuf(i32 %13, i32* null)
br label %15
15: ; preds = %31, %2
%16 = phi i64 [ %33, %31 ], [ 0, %2 ]
%17 = phi i64 [ %19, %31 ], [ 0, %2 ]
br label %18
18: ; preds = %15, %28
%19 = phi i64 [ %17, %15 ], [ %30, %28 ]
br label %20
20: ; preds = %27, %18
%21 = call double @mem_worker(i64 %19, i64 %16, %struct.timespec* %6)
%22 = call i32 @get_usr_input(i8* %7, i32* %4)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call signext i8 @interpret_command(i8* %7, x86_fp80* %5)
%26 = sext i8 %25 to i32
switch i32 %26, label %27 [
i32 109, label %28
i32 113, label %34
i32 116, label %31
]
27: ; preds = %24, %20
br label %20
28: ; preds = %24
%29 = load x86_fp80, x86_fp80* %5
%30 = fptosi x86_fp80 %29 to i64
br label %18
31: ; preds = %24
%32 = load x86_fp80, x86_fp80* %5
%33 = fptosi x86_fp80 %32 to i64
br label %15
34: ; preds = %24
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}