#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 *, int, int);
int read_copy_size4(struct tracecmd_input *, int);
int copy_proc_kallsyms(struct tracecmd_input *handle, int fd) {
  int size;
  size = read_copy_size4(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_proc_kallsyms>:
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_size4@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1154 <copy_proc_kallsyms+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1196 <copy_proc_kallsyms+0x76>
cmpl   $0x0,-0x18(%rbp)
jge    116a <copy_proc_kallsyms+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <copy_proc_kallsyms+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <read_copy_data@plt>
cmp    $0x0,%rax
jge    118f <copy_proc_kallsyms+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <copy_proc_kallsyms+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_proc_kallsyms>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <read_copy_size4@plt>
test   %eax,%eax
je     1145 <copy_proc_kallsyms+0x25>
js     1149 <copy_proc_kallsyms+0x29>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1030 <read_copy_data@plt>
sar    $0x3f,%rax
jmp    114e <copy_proc_kallsyms+0x2e>
xor    %eax,%eax
jmp    114e <copy_proc_kallsyms+0x2e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tracecmd_input = type { i32 }
define i32 @copy_proc_kallsyms(%struct.tracecmd_input* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tracecmd_input*
%5 = alloca i32
%6 = alloca i32
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 i32 @read_copy_size4(%struct.tracecmd_input* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %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 i32, i32* %6
%15 = icmp slt i32 %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 i32, i32* %6
%20 = load i32, i32* %5
%21 = call i64 @read_copy_data(%struct.tracecmd_input* %18, i32 %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_proc_kallsyms(%struct.tracecmd_input* %0, i32 %1) {
%3 = tail call i32 @read_copy_size4(%struct.tracecmd_input* %0, i32 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = icmp slt i32 %3, 0
br i1 %6, label %11, label %7
7: ; preds = %5
%8 = tail call i64 @read_copy_data(%struct.tracecmd_input* %0, i32 %3, i32 %1)
%9 = ashr i64 %8, 63
%10 = trunc i64 %9 to i32
br label %11
11: ; preds = %7, %5, %2
%12 = phi i32 [ 0, %2 ], [ -1, %5 ], [ %10, %7 ]
ret i32 %12
}