#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 */
struct tracecmd_input {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int read4(struct tracecmd_input *);
unsigned long long read8(struct tracecmd_input *);
int read_event_file(struct tracecmd_input *, char *, unsigned long long, int);
char *read_string(struct tracecmd_input *);
int read_event_files(struct tracecmd_input *handle, int print) {
  unsigned long long size;
  char *system;
  int systems;
  int count;
  int ret;
  int i, x;
  systems = read4(handle);
  if (systems < 0)
    return -1;
  for (i = 0; i < systems; i++) {
    system = read_string(handle);
    if (!system)
      return -1;
    if (print)
      printf("\nsystem: %s\n", system);
    count = read4(handle);
    if (count < 0)
      goto failed;
    for (x = 0; x < count; x++) {
      size = read8(handle);
      if (size < 0)
        goto failed;
      ret = read_event_file(handle, system, size, print);
      if (ret < 0)
        goto failed;
    }
    free(system);
  }
  return 0;
failed:
  free(system);
  return -1;
}


x86 assembly (clang, -O0):
<read_event_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <read4@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1191 <read_event_files+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <read_event_files+0x139>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    127d <read_event_files+0x11d>
mov    -0x10(%rbp),%rdi
call   1080 <read_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <read_event_files+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <read_event_files+0x139>
cmpl   $0x0,-0x14(%rbp)
je     11e2 <read_event_files+0x82>
mov    -0x28(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <read4@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11fd <read_event_files+0x9d>
jmp    1289 <read_event_files+0x129>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1266 <read_event_files+0x106>
mov    -0x10(%rbp),%rdi
call   1060 <read8@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jae    122d <read_event_files+0xcd>
jmp    1289 <read_event_files+0x129>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1070 <read_event_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1253 <read_event_files+0xf3>
jmp    1289 <read_event_files+0x129>
jmp    1258 <read_event_files+0xf8>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1204 <read_event_files+0xa4>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1198 <read_event_files+0x38>
movl   $0x0,-0x4(%rbp)
jmp    1299 <read_event_files+0x139>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_event_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%rbx
call   1040 <read4@plt>
mov    %eax,%r15d
mov    $0xffffffff,%eax
test   %r15d,%r15d
js     1226 <read_event_files+0xc6>
je     1224 <read_event_files+0xc4>
xor    %r14d,%r14d
jmp    11b1 <read_event_files+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%r14d
cmp    %r15d,%r14d
je     1224 <read_event_files+0xc4>
mov    %rbx,%rdi
call   1080 <read_string@plt>
test   %rax,%rax
je     121d <read_event_files+0xbd>
mov    %rax,%rbp
test   %r13d,%r13d
je     11d5 <read_event_files+0x75>
lea    0xe33(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <read4@plt>
test   %eax,%eax
js     1215 <read_event_files+0xb5>
mov    %eax,%r12d
je     11a0 <read_event_files+0x40>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <read8@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
mov    %r13d,%ecx
call   1070 <read_event_file@plt>
test   %eax,%eax
js     1215 <read_event_files+0xb5>
add    $0xffffffff,%r12d
jne    11f0 <read_event_files+0x90>
jmp    11a0 <read_event_files+0x40>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
jmp    1226 <read_event_files+0xc6>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tracecmd_input = type { i32 }
@.str = [13 x i8] c"\0Asystem: %s\0A\00"
define i32 @read_event_files(%struct.tracecmd_input* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tracecmd_input*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.tracecmd_input* %0, %struct.tracecmd_input** %4
store i32 %1, i32* %5
%13 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%14 = call i32 @read4(%struct.tracecmd_input* %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %75
18: ; preds = %2
store i32 0, i32* %11
br label %19
19: ; preds = %68, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %71
23: ; preds = %19
%24 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%25 = call i8* @read_string(%struct.tracecmd_input* %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %23
store i32 -1, i32* %3
br label %75
29: ; preds = %23
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %29
%36 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%37 = call i32 @read4(%struct.tracecmd_input* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %72
41: ; preds = %35
store i32 0, i32* %12
br label %42
42: ; preds = %62, %41
%43 = load i32, i32* %12
%44 = load i32, i32* %9
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %65
46: ; preds = %42
%47 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%48 = call i64 @read8(%struct.tracecmd_input* %47)
store i64 %48, i64* %6
%49 = load i64, i64* %6
%50 = icmp ult i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
br label %72
52: ; preds = %46
%53 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%54 = load i8*, i8** %7
%55 = load i64, i64* %6
%56 = load i32, i32* %5
%57 = call i32 @read_event_file(%struct.tracecmd_input* %53, i8* %54, i64 %55, i32 %56)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %52
br label %72
61: ; preds = %52
br label %62
62: ; preds = %61
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %42
65: ; preds = %42
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
br label %68
68: ; preds = %65
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %19
71: ; preds = %19
store i32 0, i32* %3
br label %75
72: ; preds = %60, %51, %40
%73 = load i8*, i8** %7
%74 = call i32 @free(i8* %73)
store i32 -1, i32* %3
br label %75
75: ; preds = %72, %71, %28, %17
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
%struct.tracecmd_input = type { i32 }
@.str = [13 x i8] c"\0Asystem: %s\0A\00"
define i32 @read_event_files(%struct.tracecmd_input* %0, i32 %1) {
%3 = tail call i32 @read4(%struct.tracecmd_input* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = icmp eq i32 %3, 0
br i1 %6, label %35, label %7
7: ; preds = %5
%8 = icmp eq i32 %1, 0
br label %9
9: ; preds = %7, %29
%10 = phi i32 [ 0, %7 ], [ %31, %29 ]
%11 = tail call i8* @read_string(%struct.tracecmd_input* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %35, label %13
13: ; preds = %9
br i1 %8, label %16, label %14
14: ; preds = %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %16
16: ; preds = %14, %13
%17 = tail call i32 @read4(%struct.tracecmd_input* %0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %33, label %19
19: ; preds = %16
%20 = icmp eq i32 %17, 0
br i1 %20, label %29, label %23
21: ; preds = %23
%22 = icmp eq i32 %28, %17
br i1 %22, label %29, label %23
23: ; preds = %19, %21
%24 = phi i32 [ %28, %21 ], [ 0, %19 ]
%25 = tail call i64 @read8(%struct.tracecmd_input* %0)
%26 = tail call i32 @read_event_file(%struct.tracecmd_input* %0, i8* %11, i64 %25, i32 %1)
%27 = icmp slt i32 %26, 0
%28 = add nuw nsw i32 %24, 1
br i1 %27, label %33, label %21
29: ; preds = %21, %19
%30 = tail call i32 @free(i8* %11)
%31 = add nuw nsw i32 %10, 1
%32 = icmp eq i32 %31, %3
br i1 %32, label %35, label %9
33: ; preds = %16, %23
%34 = tail call i32 @free(i8* %11)
br label %35
35: ; preds = %9, %29, %5, %2, %33
%36 = phi i32 [ -1, %33 ], [ -1, %2 ], [ 0, %5 ], [ -1, %9 ], [ 0, %29 ]
ret i32 %36
}