#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 */

/* Variables and functions */
int /*<<< orphan*/ com_logPrint(char *, int);
int /*<<< orphan*/ exit(int);
int std_read(char *, int);
int std_select(int /*<<< orphan*/, int /*<<< orphan*/);
int LogTrainStdRead(char *stdbuf) {
  int ret;
  int stdbuf_len = 0;
  ret = std_select(0, 0);
  if (ret == 0) {
    return 0;
  }
  if (ret == 1) {
    stdbuf_len = std_read(stdbuf, 1024000);
    com_logPrint("std_read()=%d", stdbuf_len);
    if (stdbuf_len <= 0) {
      exit(1);
    }
    return stdbuf_len;
  }
  return -2;
}


x86 assembly (clang, -O0):
<LogTrainStdRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1060 <std_select@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1175 <LogTrainStdRead+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <LogTrainStdRead+0x85>
cmpl   $0x1,-0x14(%rbp)
jne    11be <LogTrainStdRead+0x7e>
mov    -0x10(%rbp),%rdi
mov    $0xfa000,%esi
call   1030 <std_read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe66(%rip),%rdi
call   1040 <com_logPrint@plt>
cmpl   $0x0,-0x18(%rbp)
jg     11b3 <LogTrainStdRead+0x73>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <LogTrainStdRead+0x85>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LogTrainStdRead>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
xor    %esi,%esi
call   1060 <std_select@plt>
mov    %eax,%ebx
test   %eax,%eax
je     118b <LogTrainStdRead+0x4b>
cmp    $0x1,%ebx
jne    1186 <LogTrainStdRead+0x46>
mov    %r14,%rdi
mov    $0xfa000,%esi
call   1030 <std_read@plt>
mov    %eax,%ebx
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
call   1040 <com_logPrint@plt>
test   %ebx,%ebx
jg     118b <LogTrainStdRead+0x4b>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"std_read()=%d\00"
define i32 @LogTrainStdRead(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%6 = call i32 @std_select(i32 0, i32 0)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %25
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i32 @std_read(i8* %14, i32 1024000)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i32 @com_logPrint(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* %5
store i32 %23, i32* %2
br label %25
24: ; preds = %10
store i32 -2, i32* %2
br label %25
25: ; preds = %24, %22, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [14 x i8] c"std_read()=%d\00"
define i32 @LogTrainStdRead(i8* %0) {
%2 = tail call i32 @std_select(i32 0, i32 0)
switch i32 %2, label %9 [
i32 0, label %10
i32 1, label %3
]
3: ; preds = %1
%4 = tail call i32 @std_read(i8* %0, i32 1024000)
%5 = tail call i32 @com_logPrint(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %4, 1
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
br label %10
10: ; preds = %3, %1, %9
%11 = phi i32 [ -2, %9 ], [ %2, %1 ], [ %4, %3 ]
ret i32 %11
}