#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 */
typedef int /*<<< orphan*/ inbuf;

/* Variables and functions */
int /*<<< orphan*/ com_logPrint(char *, int);
int tcp_read(char *, int);
int tcp_select(int /*<<< orphan*/, int);
int LogTrainTcpRead(int tm) {
  int i;
  int ret;
  char inbuf[1024];
  ret = tcp_select(0, tm);
  if (ret == 0) {
    return 0;
  }
  if (ret == 1) {
    ret = tcp_read((char *)&inbuf, sizeof(inbuf));
    com_logPrint("tcp_read()=%d", ret);
    if (ret <= 0) {
      return -1;
    }
    return 1;
  }
  return -2;
}


x86 assembly (clang, -O0):
<LogTrainTcpRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
xor    %edi,%edi
call   1030 <tcp_select@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1161 <LogTrainTcpRead+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <LogTrainTcpRead+0x87>
cmpl   $0x1,-0x10(%rbp)
jne    11b0 <LogTrainTcpRead+0x80>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1040 <tcp_read@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1050 <com_logPrint@plt>
cmpl   $0x0,-0x10(%rbp)
jg     11a4 <LogTrainTcpRead+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <LogTrainTcpRead+0x87>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <LogTrainTcpRead+0x87>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LogTrainTcpRead>:
push   %rbx
sub    $0x400,%rsp
mov    %edi,%esi
xor    %edi,%edi
call   1030 <tcp_select@plt>
test   %eax,%eax
je     117a <LogTrainTcpRead+0x4a>
cmp    $0x1,%eax
jne    1175 <LogTrainTcpRead+0x45>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <tcp_read@plt>
mov    %eax,%ebx
lea    0xea0(%rip),%rdi
mov    %eax,%esi
call   1050 <com_logPrint@plt>
xor    %eax,%eax
test   %ebx,%ebx
setg   %al
add    %eax,%eax
add    $0xffffffff,%eax
jmp    117a <LogTrainTcpRead+0x4a>
mov    $0xfffffffe,%eax
add    $0x400,%rsp
pop    %rbx
ret

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

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