#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*/ evt_store(int, int, int, int);
int /*<<< orphan*/ evt_store_dl(int, int, int, int, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ *name_get(int, int);
int /*<<< orphan*/ name_register(int, int, char const *);
int /*<<< orphan*/ stderr;
int task_dline(int /*<<< orphan*/ *);
char *task_name(int /*<<< orphan*/ *);
int trace_common(int /*<<< orphan*/ *, int *, int *, int *, int *);
int trace_common_nocpu(int /*<<< orphan*/ *, int *, int *, int *);
int trace_read(FILE *f, int nocpu) {
  int type, time, task, cpu, res, old_dl = 0, new_dl = 0;
  const char *name;
  if (nocpu) {
    res = trace_common_nocpu(f, &type, &time, &task);
    cpu = 0;
  } else {
    res = trace_common(f, &type, &time, &task, &cpu);
  }
  if (res < 0) {
    return res;
  }
  switch (type) {
  case 0:
  case 11:
  case 12:
  case 1:
  case 3:
  case 13:
  case 2:
  case 10:
    evt_store(type, time, task, cpu);
    break;
  case 9:
    name = task_name(f);
    name_register(task, cpu, name);
    evt_store(type, time, task, cpu);
    break;
  case 4:
    old_dl = task_dline(f);
  case 5:
    new_dl = task_dline(f);
    if (name_get(task, cpu) == NULL) {
      return -5;
    }
    evt_store_dl(type, time, task, cpu, old_dl, new_dl);
    break;
  default:
    fprintf(stderr, "trace_read: Strange event type %d\n", type);
    return -4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<trace_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11db <trace_read+0x4b>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <trace_common_nocpu@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    11f7 <trace_read+0x67>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   10b0 <trace_common@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    120c <trace_read+0x7c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12fb <trace_read+0x16b>
mov    -0x18(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0xd,%rax
ja     12d0 <trace_read+0x140>
mov    -0x40(%rbp),%rax
lea    0xdd8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   10a0 <evt_store@plt>
jmp    12f4 <trace_read+0x164>
mov    -0x10(%rbp),%rdi
call   1030 <task_name@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   1080 <name_register@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   10a0 <evt_store@plt>
jmp    12f4 <trace_read+0x164>
mov    -0x10(%rbp),%rdi
call   1060 <task_dline@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <task_dline@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <name_get@plt>
cmp    $0x0,%rax
jne    12b2 <trace_read+0x122>
movl   $0xfffffffb,-0x4(%rbp)
jmp    12fb <trace_read+0x16b>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
call   1090 <evt_store_dl@plt>
jmp    12f4 <trace_read+0x164>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd55(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    12fb <trace_read+0x16b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_read>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
test   %esi,%esi
je     11c2 <trace_read+0x32>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1040 <trace_common_nocpu@plt>
movl   $0x0,0x8(%rsp)
test   %eax,%eax
jns    11e2 <trace_read+0x52>
jmp    1213 <trace_read+0x83>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
call   10b0 <trace_common@plt>
test   %eax,%eax
js     1213 <trace_read+0x83>
mov    0x14(%rsp),%eax
cmp    $0xd,%rax
ja     125d <trace_read+0xcd>
xor    %ebp,%ebp
lea    0xe0b(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %eax,%edi
call   10a0 <evt_store@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
call   1060 <task_dline@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <task_dline@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1070 <name_get@plt>
test   %rax,%rax
je     12a8 <trace_read+0x118>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %ebp,%r8d
mov    %ebx,%r9d
call   1090 <evt_store_dl@plt>
jmp    1211 <trace_read+0x81>
mov    0x2d7c(%rip),%rcx
mov    (%rcx),%edi
lea    0xdcb(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0xfffffffc,%eax
jmp    1213 <trace_read+0x83>
mov    %rbx,%rdi
call   1030 <task_name@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    %rax,%rdx
call   1080 <name_register@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
jmp    120c <trace_read+0x7c>
mov    $0xfffffffb,%eax
jmp    1213 <trace_read+0x83>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"trace_read: Strange event type %d\0A\00"
define i32 @trace_read(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 0, i32* %11
store i32 0, i32* %12
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32*, i32** %4
%18 = call i32 @trace_common_nocpu(i32* %17, i32* %6, i32* %7, i32* %8)
store i32 %18, i32* %10
store i32 0, i32* %9
br label %22
19: ; preds = %2
%20 = load i32*, i32** %4
%21 = call i32 @trace_common(i32* %20, i32* %6, i32* %7, i32* %8, i32* %9)
store i32 %21, i32* %10
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %10
store i32 %26, i32* %3
br label %71
27: ; preds = %22
%28 = load i32, i32* %6
switch i32 %28, label %66 [
i32 0, label %29
i32 11, label %29
i32 12, label %29
i32 1, label %29
i32 3, label %29
i32 13, label %29
i32 2, label %29
i32 10, label %29
i32 9, label %35
i32 4, label %47
i32 5, label %50
]
29: ; preds = %27, %27, %27, %27, %27, %27, %27, %27
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = call i32 @evt_store(i32 %30, i32 %31, i32 %32, i32 %33)
br label %70
35: ; preds = %27
%36 = load i32*, i32** %4
%37 = call i8* @task_name(i32* %36)
store i8* %37, i8** %13
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = load i8*, i8** %13
%41 = call i32 @name_register(i32 %38, i32 %39, i8* %40)
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = call i32 @evt_store(i32 %42, i32 %43, i32 %44, i32 %45)
br label %70
47: ; preds = %27
%48 = load i32*, i32** %4
%49 = call i32 @task_dline(i32* %48)
store i32 %49, i32* %11
br label %50
50: ; preds = %27, %47
%51 = load i32*, i32** %4
%52 = call i32 @task_dline(i32* %51)
store i32 %52, i32* %12
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = call i32* @name_get(i32 %53, i32 %54)
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 -5, i32* %3
br label %71
58: ; preds = %50
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = call i32 @evt_store_dl(i32 %59, i32 %60, i32 %61, i32 %62, i32 %63, i32 %64)
br label %70
66: ; preds = %27
%67 = load i32, i32* @stderr
%68 = load i32, i32* %6
%69 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %68)
store i32 -4, i32* %3
br label %71
70: ; preds = %58, %35, %29
store i32 0, i32* %3
br label %71
71: ; preds = %70, %66, %57, %25
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"trace_read: Strange event type %d\0A\00"
define i32 @trace_read(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %1, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @trace_common_nocpu(i32* %0, i32* %3, i32* %4, i32* %5)
store i32 0, i32* %6
br label %16
14: ; preds = %2
%15 = call i32 @trace_common(i32* %0, i32* %3, i32* %4, i32* %5, i32* %6)
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
%18 = icmp slt i32 %17, 0
br i1 %18, label %54, label %19
19: ; preds = %16
%20 = load i32, i32* %3
switch i32 %20, label %51 [
i32 0, label %21
i32 11, label %21
i32 12, label %21
i32 1, label %21
i32 3, label %21
i32 13, label %21
i32 2, label %21
i32 10, label %21
i32 9, label %26
i32 4, label %36
i32 5, label %38
]
21: ; preds = %19, %19, %19, %19, %19, %19, %19, %19
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @evt_store(i32 %20, i32 %22, i32 %23, i32 %24)
br label %54
26: ; preds = %19
%27 = call i8* @task_name(i32* %0)
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @name_register(i32 %28, i32 %29, i8* %27)
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 @evt_store(i32 %31, i32 %32, i32 %33, i32 %34)
br label %54
36: ; preds = %19
%37 = call i32 @task_dline(i32* %0)
br label %38
38: ; preds = %19, %36
%39 = phi i32 [ 0, %19 ], [ %37, %36 ]
%40 = call i32 @task_dline(i32* %0)
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = call i32* @name_get(i32 %41, i32 %42)
%44 = icmp eq i32* %43, null
br i1 %44, label %54, label %45
45: ; preds = %38
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 @evt_store_dl(i32 %46, i32 %47, i32 %48, i32 %49, i32 %39, i32 %40)
br label %54
51: ; preds = %19
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %54
54: ; preds = %21, %26, %45, %38, %16, %51
%55 = phi i32 [ -4, %51 ], [ %17, %16 ], [ -5, %38 ], [ 0, %45 ], [ 0, %26 ], [ 0, %21 ]
ret i32 %55
}