#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 *, ...);
int check_executed_fifo(FILE *in, int num_threads, int num_iterations) {
  char buf[1024];
  unsigned long prev_thread = 0;
  int counter = 0;
  while (!feof(in)) {
    unsigned long thread_id;
    int iter;
    char nl;
    fgets(buf, 1024, in);
    if (sscanf(buf, "Thread %lu: loop %i%c", &thread_id, &iter, &nl) == 3) {
      if (prev_thread == 0)
        prev_thread = thread_id;
      else if (prev_thread != thread_id)
        return 0;
      counter++;
    } else if (sscanf(buf, "Thread %lu: exiting%c", &thread_id, &nl) == 2) {
      if (counter != num_iterations)
        return 0;
      prev_thread = 0;
      counter = 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_executed_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movq   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1178 <check_executed_fifo+0x48>
jmp    1280 <check_executed_fifo+0x150>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x438(%rbp),%rdx
lea    -0x43c(%rbp),%rcx
lea    -0x43d(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    121a <check_executed_fifo+0xea>
cmpq   $0x0,-0x428(%rbp)
jne    11e1 <check_executed_fifo+0xb1>
mov    -0x438(%rbp),%rax
mov    %rax,-0x428(%rbp)
jmp    1206 <check_executed_fifo+0xd6>
mov    -0x428(%rbp),%rax
cmp    -0x438(%rbp),%rax
je     1201 <check_executed_fifo+0xd1>
movl   $0x0,-0x4(%rbp)
jmp    1287 <check_executed_fifo+0x157>
jmp    1206 <check_executed_fifo+0xd6>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    127b <check_executed_fifo+0x14b>
lea    -0x420(%rbp),%rdi
lea    0xdee(%rip),%rsi
lea    -0x438(%rbp),%rdx
lea    -0x43d(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    1276 <check_executed_fifo+0x146>
mov    -0x42c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1261 <check_executed_fifo+0x131>
movl   $0x0,-0x4(%rbp)
jmp    1287 <check_executed_fifo+0x157>
movq   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
jmp    127b <check_executed_fifo+0x14b>
jmp    115a <check_executed_fifo+0x2a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_executed_fifo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edx,%ebp
mov    %rdi,%rbx
call   1040 <feof@plt>
mov    $0x1,%ecx
test   %eax,%eax
jne    1207 <check_executed_fifo+0xd7>
mov    %ebp,0xc(%rsp)
lea    0x20(%rsp),%rbp
lea    0x10(%rsp),%r13
lea    0xb(%rsp),%r15
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    1186 <check_executed_fifo+0x56>
mov    %rax,%r14
add    $0x1,%r12d
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    11fe <check_executed_fifo+0xce>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
mov    %rbp,%rdi
lea    0xe60(%rip),%rsi
mov    %r13,%rdx
lea    0x1c(%rsp),%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    11d0 <check_executed_fifo+0xa0>
mov    0x10(%rsp),%rax
test   %r14,%r14
je     1173 <check_executed_fifo+0x43>
cmp    %rax,%r14
je     1176 <check_executed_fifo+0x46>
jmp    1205 <check_executed_fifo+0xd5>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xe3c(%rip),%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    117a <check_executed_fifo+0x4a>
cmp    0xc(%rsp),%r12d
jne    1205 <check_executed_fifo+0xd5>
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    117a <check_executed_fifo+0x4a>
mov    $0x1,%ecx
jmp    1207 <check_executed_fifo+0xd7>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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