#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ cause(int *, int *);
double comprimento_medio_fila(char *);
double expntl(float);
int /*<<< orphan*/ facility(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double periodo_medio_ocupado(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ release(char *, int);
int /*<<< orphan*/ request(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ schedule(int, double, int);
int /*<<< orphan*/ *sendto(int /*<<< orphan*/ *);
int /*<<< orphan*/ smpl(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stream(int);
double time();
double utilizacao_recurso(char *);
main() {
  float Te = 100000;
  int Event = 1, Customer = 1, Aleatorio;
  float Ta0 = 10, Ts0 = 10;
  int i = 0;
  FILE *p, *saida;
  saida = fopen("TESTE.out", "w");
  if ((p = sendto(saida)) == NULL)
    printf("Erro na saida \n");
  smpl(0, " TESTE");
  facility("CS_0", 1);
  stream(1);
  schedule(1, 0.0, Customer);
  while ((time() < Te)) {
    cause(&Event, &Customer);
    switch (Event) {
    case 1:
      schedule(2, 0.0, Customer);
      schedule(1, expntl(Ta0), Customer);
      break;
    case 2:
      if (request("CS_0", Event, Customer, 0) == 0)
        schedule(3, expntl(Ts0), Customer);
      break;
    case 3:
      release("CS_0", Customer);
      break;
    }
  }
  fprintf(saida, "TempoSimulado: %f\n", time());
  fprintf(saida, "Utilizacao (\"CS_0\") = %g\n", utilizacao_recurso("CS_0"));
  fprintf(saida, "Comprimento medio fila (\"CS_0\") = %g\n",
          comprimento_medio_fila("CS_0"));
  fprintf(saida, "Periodo medio ocupado (\"CS_0\") = %g\n",
          periodo_medio_ocupado("CS_0"));
  fclose(saida);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xddd(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movss  0xdbe(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xdb1(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xda6(%rip),%rdi
lea    0xda9(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <sendto@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1295 <main+0x85>
lea    0xd84(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
lea    0xd86(%rip),%rsi
call   1090 <smpl@plt>
lea    0xd81(%rip),%rdi
mov    $0x1,%esi
call   10d0 <facility@plt>
mov    $0x1,%edi
call   10b0 <stream@plt>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
xorps  %xmm0,%xmm0
call   1030 <schedule@plt>
mov    $0x0,%al
call   10c0 <time@plt>
movaps %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    13a7 <main+0x197>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1130 <cause@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     132e <main+0x11e>
jmp    130c <main+0xfc>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     135a <main+0x14a>
jmp    131d <main+0x10d>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
je     1393 <main+0x183>
jmp    13a2 <main+0x192>
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
xorps  %xmm0,%xmm0
call   1030 <schedule@plt>
movss  -0x18(%rbp),%xmm0
call   1100 <expntl@plt>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1030 <schedule@plt>
jmp    13a2 <main+0x192>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xcc4(%rip),%rdi
xor    %ecx,%ecx
call   10e0 <request@plt>
cmp    $0x0,%eax
jne    138e <main+0x17e>
movss  -0x1c(%rbp),%xmm0
call   1100 <expntl@plt>
mov    -0x10(%rbp),%esi
mov    $0x3,%edi
call   1030 <schedule@plt>
jmp    13a2 <main+0x192>
mov    -0x10(%rbp),%esi
lea    0xc8e(%rip),%rdi
call   1110 <release@plt>
jmp    12ce <main+0xbe>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   10c0 <time@plt>
mov    -0x58(%rbp),%rdi
lea    0xc6f(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xc56(%rip),%rdi
call   1120 <utilizacao_recurso@plt>
mov    -0x50(%rbp),%rdi
lea    0xc5e(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xc32(%rip),%rdi
call   1040 <comprimento_medio_fila@plt>
mov    -0x48(%rbp),%rdi
lea    0xc54(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xc0e(%rip),%rdi
call   1060 <periodo_medio_ocupado@plt>
mov    -0x40(%rbp),%rdi
lea    0xc56(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
movl   $0x1,(%rsp)
lea    0xdde(%rip),%rdi
lea    0xde1(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <sendto@plt>
test   %rax,%rax
jne    1256 <main+0x46>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
lea    0xdbb(%rip),%rsi
xor    %edi,%edi
call   1090 <smpl@plt>
lea    0xdb4(%rip),%rdi
mov    $0x1,%esi
call   10d0 <facility@plt>
mov    $0x1,%edi
call   10b0 <stream@plt>
xorpd  %xmm0,%xmm0
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <schedule@plt>
xor    %eax,%eax
call   10c0 <time@plt>
movsd  0xd5f(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1365 <main+0x155>
lea    0x4(%rsp),%r15
mov    %rsp,%rbx
lea    0xd65(%rip),%r12
jmp    12e4 <main+0xd4>
nopl   0x0(%rax)
mov    (%rsp),%esi
mov    %r12,%rdi
call   1110 <release@plt>
xor    %eax,%eax
call   10c0 <time@plt>
movsd  0xd26(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1365 <main+0x155>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1130 <cause@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%eax
je     12c0 <main+0xb0>
cmp    $0x2,%eax
je     1330 <main+0x120>
cmp    $0x1,%eax
jne    12cb <main+0xbb>
mov    (%rsp),%esi
xorpd  %xmm0,%xmm0
mov    $0x2,%edi
call   1030 <schedule@plt>
movss  0xced(%rip),%xmm0
call   1100 <expntl@plt>
mov    (%rsp),%esi
mov    $0x1,%edi
call   1030 <schedule@plt>
jmp    12cb <main+0xbb>
nop
mov    (%rsp),%edx
mov    %r12,%rdi
mov    $0x2,%esi
xor    %ecx,%ecx
call   10e0 <request@plt>
test   %eax,%eax
jne    12cb <main+0xbb>
movss  0xcba(%rip),%xmm0
call   1100 <expntl@plt>
mov    (%rsp),%esi
mov    $0x3,%edi
call   1030 <schedule@plt>
jmp    12cb <main+0xbb>
xor    %eax,%eax
call   10c0 <time@plt>
lea    0xcb1(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
lea    0xc9d(%rip),%rbx
mov    %rbx,%rdi
call   1120 <utilizacao_recurso@plt>
lea    0xca6(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <comprimento_medio_fila@plt>
lea    0xca9(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <periodo_medio_ocupado@plt>
lea    0xcb8(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"TESTE.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [16 x i8] c"Erro na saida \0A\00"
@.str.3 = [7 x i8] c" TESTE\00"
@.str.4 = [5 x i8] c"CS_0\00"
@.str.5 = [19 x i8] c"TempoSimulado: %f\0A\00"
@.str.6 = [26 x i8] c"Utilizacao (\22CS_0\22) = %g\0A\00"
@.str.7 = [38 x i8] c"Comprimento medio fila (\22CS_0\22) = %g\0A\00"
@.str.8 = [37 x i8] c"Periodo medio ocupado (\22CS_0\22) = %g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %1
store float 1.000000e+05, float* %2
store i32 1, i32* %3
store i32 1, i32* %4
store float 1.000000e+01, float* %6
store float 1.000000e+01, float* %7
store i32 0, i32* %8
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %10
%12 = load i32*, i32** %10
%13 = call i32* @sendto(i32* %12)
store i32* %13, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = call i32 @smpl(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @facility(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 1)
%20 = call i32 @stream(i32 1)
%21 = load i32, i32* %4
%22 = call i32 @schedule(i32 1, double 0.000000e+00, i32 %21)
br label %23
23: ; preds = %52, %17
%24 = call double (...) @time()
%25 = load float, float* %2
%26 = fpext float %25 to double
%27 = fcmp olt double %24, %26
br i1 %27, label %28, label %53
28: ; preds = %23
%29 = call i32 @cause(i32* %3, i32* %4)
%30 = load i32, i32* %3
switch i32 %30, label %52 [
i32 1, label %31
i32 2, label %38
i32 3, label %49
]
31: ; preds = %28
%32 = load i32, i32* %4
%33 = call i32 @schedule(i32 2, double 0.000000e+00, i32 %32)
%34 = load float, float* %6
%35 = call double @expntl(float %34)
%36 = load i32, i32* %4
%37 = call i32 @schedule(i32 1, double %35, i32 %36)
br label %52
38: ; preds = %28
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = call i32 @request(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40, i32 0)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load float, float* %7
%45 = call double @expntl(float %44)
%46 = load i32, i32* %4
%47 = call i32 @schedule(i32 3, double %45, i32 %46)
br label %48
48: ; preds = %43, %38
br label %52
49: ; preds = %28
%50 = load i32, i32* %4
%51 = call i32 @release(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %28, %49, %48, %31
br label %23
53: ; preds = %23
%54 = load i32*, i32** %10
%55 = call double (...) @time()
%56 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %55)
%57 = load i32*, i32** %10
%58 = call double @utilizacao_recurso(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @fprintf(i32* %57, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), double %58)
%60 = load i32*, i32** %10
%61 = call double @comprimento_medio_fila(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @fprintf(i32* %60, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), double %61)
%63 = load i32*, i32** %10
%64 = call double @periodo_medio_ocupado(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%65 = call i32 @fprintf(i32* %63, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), double %64)
%66 = load i32*, i32** %10
%67 = call i32 @fclose(i32* %66)
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str = [10 x i8] c"TESTE.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c" TESTE\00"
@.str.4 = [5 x i8] c"CS_0\00"
@.str.5 = [19 x i8] c"TempoSimulado: %f\0A\00"
@.str.6 = [26 x i8] c"Utilizacao (\22CS_0\22) = %g\0A\00"
@.str.7 = [38 x i8] c"Comprimento medio fila (\22CS_0\22) = %g\0A\00"
@.str.8 = [37 x i8] c"Periodo medio ocupado (\22CS_0\22) = %g\0A\00"
@str = [15 x i8] c"Erro na saida \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @sendto(i32* %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @smpl(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @facility(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 1)
%13 = tail call i32 @stream(i32 1)
%14 = tail call i32 @schedule(i32 1, double 0.000000e+00, i32 1)
%15 = call double (...) @time()
%16 = fcmp olt double %15, 1.000000e+05
br i1 %16, label %17, label %40
17: ; preds = %10, %37
%18 = call i32 @cause(i32* %1, i32* %2)
%19 = load i32, i32* %1
switch i32 %19, label %37 [
i32 1, label %20
i32 2, label %26
i32 3, label %34
]
20: ; preds = %17
%21 = load i32, i32* %2
%22 = call i32 @schedule(i32 2, double 0.000000e+00, i32 %21)
%23 = call double @expntl(float 1.000000e+01)
%24 = load i32, i32* %2
%25 = call i32 @schedule(i32 1, double %23, i32 %24)
br label %37
26: ; preds = %17
%27 = load i32, i32* %2
%28 = call i32 @request(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %27, i32 0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = call double @expntl(float 1.000000e+01)
%32 = load i32, i32* %2
%33 = call i32 @schedule(i32 3, double %31, i32 %32)
br label %37
34: ; preds = %17
%35 = load i32, i32* %2
%36 = call i32 @release(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %26, %30, %17, %34, %20
%38 = call double (...) @time()
%39 = fcmp olt double %38, 1.000000e+05
br i1 %39, label %17, label %40
40: ; preds = %37, %10
%41 = call double (...) @time()
%42 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %41)
%43 = call double @utilizacao_recurso(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), double %43)
%45 = call double @comprimento_medio_fila(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), double %45)
%47 = call double @periodo_medio_ocupado(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), double %47)
%49 = call i32 @fclose(i32* %5)
ret i32 0
}