#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, int);
unsigned long read_copy_size8(struct tracecmd_input *, int);
int copy_command_lines(struct tracecmd_input *handle, int fd) {
  unsigned long size;
  size = read_copy_size8(handle, fd);
  if (!size)
    return 0;
  if (size < 0)
    return -1;
  if (read_copy_data(handle, size, fd) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<copy_command_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <read_copy_size8@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1156 <copy_command_lines+0x36>
movl   $0x0,-0x4(%rbp)
jmp    119a <copy_command_lines+0x7a>
cmpq   $0x0,-0x20(%rbp)
jae    116d <copy_command_lines+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <copy_command_lines+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read_copy_data@plt>
cmp    $0x0,%rax
jge    1193 <copy_command_lines+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <copy_command_lines+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_command_lines>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <read_copy_size8@plt>
test   %rax,%rax
je     1145 <copy_command_lines+0x25>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <read_copy_data@plt>
sar    $0x3f,%rax
jmp    1147 <copy_command_lines+0x27>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tracecmd_input = type { i32 }
define i32 @copy_command_lines(%struct.tracecmd_input* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tracecmd_input*
%5 = alloca i32
%6 = alloca i64
store %struct.tracecmd_input* %0, %struct.tracecmd_input** %4
store i32 %1, i32* %5
%7 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%8 = load i32, i32* %5
%9 = call i64 @read_copy_size8(%struct.tracecmd_input* %7, i32 %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp ne i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %25
13: ; preds = %2
%14 = load i64, i64* %6
%15 = icmp ult i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %3
br label %25
17: ; preds = %13
%18 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%19 = load i64, i64* %6
%20 = load i32, i32* %5
%21 = call i64 @read_copy_data(%struct.tracecmd_input* %18, i64 %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %3
br label %25
24: ; preds = %17
store i32 0, i32* %3
br label %25
25: ; preds = %24, %23, %16, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.tracecmd_input = type { i32 }
define i32 @copy_command_lines(%struct.tracecmd_input* %0, i32 %1) {
%3 = tail call i64 @read_copy_size8(%struct.tracecmd_input* %0, i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i64 @read_copy_data(%struct.tracecmd_input* %0, i64 %3, i32 %1)
%7 = ashr i64 %6, 63
%8 = trunc i64 %7 to i32
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ 0, %2 ], [ %8, %5 ]
ret i32 %10
}