#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 */
scalar_t__ read_copy_data(struct tracecmd_input *, unsigned long long, int);
int read_copy_size4(struct tracecmd_input *, int);
unsigned long long read_copy_size8(struct tracecmd_input *, int);
int copy_ftrace_files(struct tracecmd_input *handle, int fd) {
  unsigned long long size;
  int count;
  int i;
  count = read_copy_size4(handle, fd);
  if (count < 0)
    return -1;
  for (i = 0; i < count; i++) {
    size = read_copy_size8(handle, fd);
    if (size < 0)
      return -1;
    if (read_copy_data(handle, size, fd) < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_ftrace_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <read_copy_size4@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1164 <copy_ftrace_files+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <copy_ftrace_files+0xae>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d7 <copy_ftrace_files+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <read_copy_size8@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jae    119e <copy_ftrace_files+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <copy_ftrace_files+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read_copy_data@plt>
cmp    $0x0,%rax
jge    11c4 <copy_ftrace_files+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <copy_ftrace_files+0xae>
jmp    11c9 <copy_ftrace_files+0x99>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116b <copy_ftrace_files+0x3b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_ftrace_files>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
call   1040 <read_copy_size4@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1186 <copy_ftrace_files+0x56>
mov    %eax,%ebp
test   %eax,%eax
je     1183 <copy_ftrace_files+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <read_copy_size8@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1030 <read_copy_data@plt>
test   %rax,%rax
js     1186 <copy_ftrace_files+0x56>
add    $0xffffffff,%ebp
jne    1160 <copy_ftrace_files+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tracecmd_input = type { i32 }
define i32 @copy_ftrace_files(%struct.tracecmd_input* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tracecmd_input*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store %struct.tracecmd_input* %0, %struct.tracecmd_input** %4
store i32 %1, i32* %5
%9 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%10 = load i32, i32* %5
%11 = call i32 @read_copy_size4(%struct.tracecmd_input* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %39
15: ; preds = %2
store i32 0, i32* %8
br label %16
16: ; preds = %35, %15
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%22 = load i32, i32* %5
%23 = call i64 @read_copy_size8(%struct.tracecmd_input* %21, i32 %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = icmp ult i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %3
br label %39
27: ; preds = %20
%28 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%29 = load i64, i64* %6
%30 = load i32, i32* %5
%31 = call i64 @read_copy_data(%struct.tracecmd_input* %28, i64 %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 -1, i32* %3
br label %39
34: ; preds = %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %16
38: ; preds = %16
store i32 0, i32* %3
br label %39
39: ; preds = %38, %33, %26, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.tracecmd_input = type { i32 }
define i32 @copy_ftrace_files(%struct.tracecmd_input* %0, i32 %1) {
%3 = tail call i32 @read_copy_size4(%struct.tracecmd_input* %0, i32 %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = icmp eq i32 %3, 0
br i1 %6, label %15, label %9
7: ; preds = %9
%8 = icmp eq i32 %14, %3
br i1 %8, label %15, label %9
9: ; preds = %5, %7
%10 = phi i32 [ %14, %7 ], [ 0, %5 ]
%11 = tail call i64 @read_copy_size8(%struct.tracecmd_input* %0, i32 %1)
%12 = tail call i64 @read_copy_data(%struct.tracecmd_input* %0, i64 %11, i32 %1)
%13 = icmp slt i64 %12, 0
%14 = add nuw nsw i32 %10, 1
br i1 %13, label %15, label %7
15: ; preds = %9, %7, %5, %2
%16 = phi i32 [ -1, %2 ], [ 0, %5 ], [ -1, %9 ], [ 0, %7 ]
ret i32 %16
}