#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 */

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int);
double exponential(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rand_val(int);
double strtod(char *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 5) {
    printf(" Please provide the following arguments: simulation time, mean "
           "time between arrivals, and mean service time \n");
    exit(1);
  }
  double simulationTime = strtod(argv[1], NULL);
  double end_time = simulationTime;
  double Ta = strtod(argv[2], NULL);
  double Ts = strtod(argv[3], NULL);
  unsigned int buf = atoi(argv[4]);
  double time = 0.0;
  double t1 = 0.0;
  double t2 = simulationTime;
  unsigned int n = 0;
  unsigned int c = 0;
  double b = 0.0;
  double s = 0.0;
  double tn = time;
  double tb;
  double x;
  double u;
  double l;
  double w;
  int flag = 0;
  rand_val(1);
  unsigned int max_buf = 0;
  while (time < end_time) {
    if (t1 < t2) {
      time = t1;
      s = s + n * (time - tn);
      n++;
      tn = time;
      t1 = time + exponential(Ta);
      if (n == 1) {
        tb = time;
        t2 = time + exponential(Ts);
      }
    } else {
      time = t2;
      s = s + n * (time - tn);
      n--;
      tn = time;
      c++;
      if (n > 0)
        t2 = time + exponential(Ts);
      else {
        t2 = simulationTime;
        b = b + time - tb;
      }
    }
    if (max_buf < n)
      max_buf = n;
    if (n > buf) {
      flag = 1;
      break;
    }
  }
  printf("%3.2f,%3.2f,%3.2f,%d,%d,%d,%d,%3.2f\n", simulationTime, Ta, Ts, buf,
         n, max_buf, flag, tn);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     119b <main+0x3b>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    $0x1,%edi
call   1030 <rand_val@plt>
movl   $0x0,-0xa0(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    140e <main+0x2ae>
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    132f <main+0x1cf>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x68(%rbp),%xmm1
mov    -0x54(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  -0x40(%rbp),%xmm2
subsd  -0x70(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
call   1060 <exponential@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x1,-0x54(%rbp)
jne    132a <main+0x1ca>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1060 <exponential@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    13d6 <main+0x276>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x68(%rbp),%xmm1
mov    -0x54(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  -0x40(%rbp),%xmm2
subsd  -0x70(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x54(%rbp)
jbe    13b3 <main+0x253>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1060 <exponential@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    13d1 <main+0x271>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
subsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    13d6 <main+0x276>
mov    -0xa0(%rbp),%eax
cmp    -0x54(%rbp),%eax
jae    13ee <main+0x28e>
mov    -0x54(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x34(%rbp),%eax
jbe    1409 <main+0x2a9>
movl   $0x1,-0x9c(%rbp)
jmp    140e <main+0x2ae>
jmp    1257 <main+0xf7>
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mov    -0x34(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    -0xa0(%rbp),%ecx
mov    -0x9c(%rbp),%r8d
movsd  -0x70(%rbp),%xmm3
lea    0xc32(%rip),%rdi
mov    $0x4,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
cmp    $0x5,%edi
jne    12ce <main+0x15e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
call   1050 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rbx),%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
movsd  %xmm0,0x20(%rsp)
mov    0x18(%rbx),%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x20(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    $0x1,%edi
call   1030 <rand_val@plt>
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
movsd  0x8(%rsp),%xmm1
xorpd  %xmm3,%xmm3
xor    %ebp,%ebp
jmp    1230 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  %xmm2,0x30(%rsp)
call   1070 <exponential@plt>
movsd  0x30(%rsp),%xmm3
movapd %xmm0,%xmm2
addsd  %xmm3,%xmm2
test   %ebx,%ebx
je     1255 <main+0xe5>
add    $0x1,%ebx
movsd  0x10(%rsp),%xmm0
cmp    %ebx,%ebp
cmovb  %ebx,%ebp
movapd %xmm0,%xmm1
cmp    %r15d,%ebx
ja     1291 <main+0x121>
movsd  0x8(%rsp),%xmm0
ucomisd %xmm3,%xmm0
jbe    1297 <main+0x127>
ucomisd %xmm2,%xmm1
ja     11f0 <main+0x80>
add    $0xffffffff,%ebx
je     1283 <main+0x113>
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x10(%rsp)
jmp    1266 <main+0xf6>
movsd  %xmm2,0x28(%rsp)
mov    $0x1,%ebx
movsd  %xmm3,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1070 <exponential@plt>
movsd  0x10(%rsp),%xmm3
addsd  %xmm3,%xmm0
movsd  0x28(%rsp),%xmm2
jmp    1222 <main+0xb2>
xor    %ebx,%ebx
movsd  0x8(%rsp),%xmm0
movapd %xmm1,%xmm3
jmp    1222 <main+0xb2>
mov    $0x1,%r14d
lea    0xd62(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
mov    $0x4,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd50(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [110 x i8] c" Please provide the following arguments: simulation time, mean time between arrivals, and mean service time \0A\00"
@.str.1 = [37 x i8] c"%3.2f,%3.2f,%3.2f,%d,%d,%d,%d,%3.2f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca i32
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 5
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call double @strtod(i8* %34, i32* null)
store double %35, double* %6
%36 = load double, double* %6
store double %36, double* %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call double @strtod(i8* %39, i32* null)
store double %40, double* %8
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call double @strtod(i8* %43, i32* null)
store double %44, double* %9
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 4
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
%49 = load double, double* %6
store double %49, double* %13
store i32 0, i32* %14
store i32 0, i32* %15
store double 0.000000e+00, double* %16
store double 0.000000e+00, double* %17
%50 = load double, double* %11
store double %50, double* %18
store i32 0, i32* %24
%51 = call i32 @rand_val(i32 1)
store i32 0, i32* %25
br label %52
52: ; preds = %125, %31
%53 = load double, double* %11
%54 = load double, double* %7
%55 = fcmp olt double %53, %54
br i1 %55, label %56, label %126
56: ; preds = %52
%57 = load double, double* %12
%58 = load double, double* %13
%59 = fcmp olt double %57, %58
br i1 %59, label %60, label %85
60: ; preds = %56
%61 = load double, double* %12
store double %61, double* %11
%62 = load double, double* %17
%63 = load i32, i32* %14
%64 = uitofp i32 %63 to double
%65 = load double, double* %11
%66 = load double, double* %18
%67 = fsub double %65, %66
%68 = call double @llvm.fmuladd.f64(double %64, double %67, double %62)
store double %68, double* %17
%69 = load i32, i32* %14
%70 = add i32 %69, 1
store i32 %70, i32* %14
%71 = load double, double* %11
store double %71, double* %18
%72 = load double, double* %11
%73 = load double, double* %8
%74 = call double @exponential(double %73)
%75 = fadd double %72, %74
store double %75, double* %12
%76 = load i32, i32* %14
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %84
78: ; preds = %60
%79 = load double, double* %11
store double %79, double* %19
%80 = load double, double* %11
%81 = load double, double* %9
%82 = call double @exponential(double %81)
%83 = fadd double %80, %82
store double %83, double* %13
br label %84
84: ; preds = %78, %60
br label %114
85: ; preds = %56
%86 = load double, double* %13
store double %86, double* %11
%87 = load double, double* %17
%88 = load i32, i32* %14
%89 = uitofp i32 %88 to double
%90 = load double, double* %11
%91 = load double, double* %18
%92 = fsub double %90, %91
%93 = call double @llvm.fmuladd.f64(double %89, double %92, double %87)
store double %93, double* %17
%94 = load i32, i32* %14
%95 = add i32 %94, -1
store i32 %95, i32* %14
%96 = load double, double* %11
store double %96, double* %18
%97 = load i32, i32* %15
%98 = add i32 %97, 1
store i32 %98, i32* %15
%99 = load i32, i32* %14
%100 = icmp ugt i32 %99, 0
br i1 %100, label %101, label %106
101: ; preds = %85
%102 = load double, double* %11
%103 = load double, double* %9
%104 = call double @exponential(double %103)
%105 = fadd double %102, %104
store double %105, double* %13
br label %113
106: ; preds = %85
%107 = load double, double* %6
store double %107, double* %13
%108 = load double, double* %16
%109 = load double, double* %11
%110 = fadd double %108, %109
%111 = load double, double* %19
%112 = fsub double %110, %111
store double %112, double* %16
br label %113
113: ; preds = %106, %101
br label %114
114: ; preds = %113, %84
%115 = load i32, i32* %25
%116 = load i32, i32* %14
%117 = icmp ult i32 %115, %116
br i1 %117, label %118, label %120
118: ; preds = %114
%119 = load i32, i32* %14
store i32 %119, i32* %25
br label %120
120: ; preds = %118, %114
%121 = load i32, i32* %14
%122 = load i32, i32* %10
%123 = icmp ugt i32 %121, %122
br i1 %123, label %124, label %125
124: ; preds = %120
store i32 1, i32* %24
br label %126
125: ; preds = %120
br label %52
126: ; preds = %124, %52
%127 = load double, double* %6
%128 = load double, double* %8
%129 = load double, double* %9
%130 = load i32, i32* %10
%131 = load i32, i32* %14
%132 = load i32, i32* %25
%133 = load i32, i32* %24
%134 = load double, double* %18
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %127, double %128, double %129, i32 %130, i32 %131, i32 %132, i32 %133, double %134)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"%3.2f,%3.2f,%3.2f,%d,%d,%d,%d,%3.2f\0A\00"
@str = [109 x i8] c" Please provide the following arguments: simulation time, mean time between arrivals, and mean service time \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([109 x i8], [109 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call double @strtod(i8* nocapture %9, i32* null)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call double @strtod(i8* nocapture %12, i32* null)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call double @strtod(i8* nocapture %15, i32* null)
%17 = getelementptr inbounds i8*, i8** %1, i64 4
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = tail call i32 @rand_val(i32 1)
br label %21
21: ; preds = %44, %7
%22 = phi i32 [ 0, %7 ], [ %45, %44 ]
%23 = phi double [ %10, %7 ], [ %46, %44 ]
%24 = phi double [ 0.000000e+00, %7 ], [ %47, %44 ]
%25 = phi double [ 0.000000e+00, %7 ], [ %48, %44 ]
%26 = phi i32 [ 0, %7 ], [ %50, %44 ]
%27 = fcmp olt double %25, %10
br i1 %27, label %28, label %52
28: ; preds = %21
%29 = fcmp olt double %24, %23
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = add i32 %22, 1
%32 = tail call double @exponential(double %13)
%33 = fadd double %24, %32
%34 = icmp eq i32 %22, 0
br i1 %34, label %38, label %44
35: ; preds = %28
%36 = add i32 %22, -1
%37 = icmp eq i32 %36, 0
br i1 %37, label %44, label %38
38: ; preds = %35, %30
%39 = phi double [ %24, %30 ], [ %23, %35 ]
%40 = phi i32 [ 1, %30 ], [ %36, %35 ]
%41 = phi double [ %33, %30 ], [ %24, %35 ]
%42 = tail call double @exponential(double %16)
%43 = fadd double %39, %42
br label %44
44: ; preds = %38, %35, %30
%45 = phi i32 [ %31, %30 ], [ 0, %35 ], [ %40, %38 ]
%46 = phi double [ %23, %30 ], [ %10, %35 ], [ %43, %38 ]
%47 = phi double [ %33, %30 ], [ %24, %35 ], [ %41, %38 ]
%48 = phi double [ %24, %30 ], [ %23, %35 ], [ %39, %38 ]
%49 = icmp ult i32 %26, %45
%50 = select i1 %49, i32 %45, i32 %26
%51 = icmp ugt i32 %45, %19
br i1 %51, label %52, label %21
52: ; preds = %44, %21
%53 = phi double [ %25, %21 ], [ %48, %44 ]
%54 = phi i32 [ %22, %21 ], [ %45, %44 ]
%55 = phi i32 [ 0, %21 ], [ 1, %44 ]
%56 = phi i32 [ %26, %21 ], [ %50, %44 ]
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), double %10, double %13, double %16, i32 %19, i32 %54, i32 %56, i32 %55, double %53)
ret i32 0
}