#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int sscanf(char *, char *, unsigned long *, char *);
void compute_queue_size(FILE *in, int *final_threads, int *threads_max,
                        int *threads_min, int *admitted_threads) {
  char buf[1024];
  *final_threads = *threads_max = *threads_min = *admitted_threads = 0;
  while (!feof(in)) {
    unsigned long thread_id;
    char nl;
    fgets(buf, 1024, in);
    if (sscanf(buf, "Thread %lu: in scheduler queue%c", &thread_id, &nl) == 2) {
      admitted_threads[0]++;
      final_threads[0]++;
      if (*final_threads > *threads_max)
        *threads_max = *final_threads;
    } else if (sscanf(buf, "Thread %lu: exiting%c", &thread_id, &nl) == 2) {
      final_threads[0]--;
      if (*final_threads < *threads_min)
        *threads_min = *final_threads;
    }
  }
}


x86 assembly (clang, -O0):
<compute_queue_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1195 <compute_queue_size+0x65>
jmp    126f <compute_queue_size+0x13f>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
lea    -0x430(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    -0x438(%rbp),%rdx
lea    -0x439(%rbp),%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    120d <compute_queue_size+0xdd>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    1208 <compute_queue_size+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    126a <compute_queue_size+0x13a>
lea    -0x430(%rbp),%rdi
lea    0xe06(%rip),%rsi
lea    -0x438(%rbp),%rdx
lea    -0x439(%rbp),%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    1265 <compute_queue_size+0x135>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    1260 <compute_queue_size+0x130>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1265 <compute_queue_size+0x135>
jmp    126a <compute_queue_size+0x13a>
jmp    1177 <compute_queue_size+0x47>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_queue_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %r8,0x10(%rsp)
movl   $0x0,(%r8)
mov    %rcx,0x8(%rsp)
movl   $0x0,(%rcx)
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
call   1040 <feof@plt>
test   %eax,%eax
je     1188 <compute_queue_size+0x58>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x20(%rsp),%rbp
lea    0x18(%rsp),%r14
lea    0x7(%rsp),%r15
jmp    11ac <compute_queue_size+0x7c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    1176 <compute_queue_size+0x46>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
mov    %rbp,%rdi
lea    0xe3a(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    1200 <compute_queue_size+0xd0>
mov    0x10(%rsp),%rax
addl   $0x1,(%rax)
mov    0x0(%r13),%ecx
lea    0x1(%rcx),%eax
mov    %eax,0x0(%r13)
cmp    (%r12),%ecx
jl     11a0 <compute_queue_size+0x70>
mov    %eax,(%r12)
jmp    11a0 <compute_queue_size+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
lea    0xe17(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11a0 <compute_queue_size+0x70>
mov    0x0(%r13),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,0x0(%r13)
mov    0x8(%rsp),%rdx
cmp    (%rdx),%ecx
jg     11a0 <compute_queue_size+0x70>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
jmp    11a0 <compute_queue_size+0x70>

LLVM IR (-O0):
@.str = [33 x i8] c"Thread %lu: in scheduler queue%c\00"
@.str.1 = [22 x i8] c"Thread %lu: exiting%c\00"
define void @compute_queue_size(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [1024 x i8]
%12 = alloca i64
%13 = alloca i8
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%14 = load i32*, i32** %10
store i32 0, i32* %14
%15 = load i32*, i32** %9
store i32 0, i32* %15
%16 = load i32*, i32** %8
store i32 0, i32* %16
%17 = load i32*, i32** %7
store i32 0, i32* %17
br label %18
18: ; preds = %69, %5
%19 = load i32*, i32** %6
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %70
23: ; preds = %18
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @fgets(i8* %24, i32 1024, i32* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64* %12, i8* %13)
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %49
30: ; preds = %23
%31 = load i32*, i32** %10
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
store i32 %34, i32* %32
%35 = load i32*, i32** %7
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
%39 = load i32*, i32** %7
%40 = load i32, i32* %39
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = icmp sgt i32 %40, %42
br i1 %43, label %44, label %48
44: ; preds = %30
%45 = load i32*, i32** %7
%46 = load i32, i32* %45
%47 = load i32*, i32** %8
store i32 %46, i32* %47
br label %48
48: ; preds = %44, %30
br label %69
49: ; preds = %23
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%51 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64* %12, i8* %13)
%52 = icmp eq i32 %51, 2
br i1 %52, label %53, label %68
53: ; preds = %49
%54 = load i32*, i32** %7
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load i32, i32* %55
%57 = add nsw i32 %56, -1
store i32 %57, i32* %55
%58 = load i32*, i32** %7
%59 = load i32, i32* %58
%60 = load i32*, i32** %9
%61 = load i32, i32* %60
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %67
63: ; preds = %53
%64 = load i32*, i32** %7
%65 = load i32, i32* %64
%66 = load i32*, i32** %9
store i32 %65, i32* %66
br label %67
67: ; preds = %63, %53
br label %68
68: ; preds = %67, %49
br label %69
69: ; preds = %68, %48
br label %18
70: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"Thread %lu: in scheduler queue%c\00"
@.str.1 = [22 x i8] c"Thread %lu: exiting%c\00"
define void @compute_queue_size(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32* nocapture %4) {
%6 = alloca [1024 x i8]
%7 = alloca i64
%8 = alloca i8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
store i32 0, i32* %1
%10 = call i32 @feof(i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %5
%13 = bitcast i64* %7 to i8*
br label %14
14: ; preds = %12, %35
%15 = call i32 @fgets(i8* %9, i32 1024, i32* %0)
%16 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64* %7, i8* %8)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %1
%23 = load i32, i32* %2
%24 = icmp slt i32 %21, %23
br i1 %24, label %35, label %25
25: ; preds = %18
store i32 %22, i32* %2
br label %35
26: ; preds = %14
%27 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64* %7, i8* %8)
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %1
%31 = add nsw i32 %30, -1
store i32 %31, i32* %1
%32 = load i32, i32* %3
%33 = icmp sgt i32 %30, %32
br i1 %33, label %35, label %34
34: ; preds = %29
store i32 %31, i32* %3
br label %35
35: ; preds = %26, %34, %29, %18, %25
%36 = call i32 @feof(i32* %0)
%37 = icmp eq i32 %36, 0
br i1 %37, label %14, label %38
38: ; preds = %35, %5
ret void
}