#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 sock_ready(int, int /*<<< orphan*/ *, int *, float);
int sock_write(int, void *, size_t);
int sock_tm_write(int fd, void *buf, size_t size, float timeout) {
  int wt;
  int retval = sock_ready(fd, NULL, &wt, timeout);
  if (retval < 0)
    return -1;
  else if (retval > 0)
    return sock_write(fd, buf, size);
  return 0;
}


x86 assembly (clang, -O0):
<sock_tm_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
movss  -0x1c(%rbp),%xmm0
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1040 <sock_ready@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1166 <sock_tm_write+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <sock_tm_write+0x74>
cmpl   $0x0,-0x24(%rbp)
jle    1188 <sock_tm_write+0x68>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <sock_write@plt>
mov    %eax,-0x4(%rbp)
jmp    1194 <sock_tm_write+0x74>
jmp    118d <sock_tm_write+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_tm_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%rdx
xor    %esi,%esi
call   1040 <sock_ready@plt>
test   %eax,%eax
js     1154 <sock_tm_write+0x34>
je     1159 <sock_tm_write+0x39>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <sock_write@plt>
mov    %eax,%ebx
jmp    1159 <sock_tm_write+0x39>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sock_tm_write(i32 %0, i8* %1, i64 %2, float %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store float %3, float* %9
%12 = load i32, i32* %6
%13 = load float, float* %9
%14 = call i32 @sock_ready(i32 %12, i32* null, i32* %10, float %13)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %28
18: ; preds = %4
%19 = load i32, i32* %11
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = call i32 @sock_write(i32 %22, i8* %23, i64 %24)
store i32 %25, i32* %5
br label %28
26: ; preds = %18
br label %27
27: ; preds = %26
store i32 0, i32* %5
br label %28
28: ; preds = %27, %21, %17
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @sock_tm_write(i32 %0, i8* %1, i64 %2, float %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @sock_ready(i32 %0, i32* null, i32* %5, float %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = icmp eq i32 %7, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = call i32 @sock_write(i32 %0, i8* %1, i64 %2)
br label %13
13: ; preds = %9, %4, %11
%14 = phi i32 [ %12, %11 ], [ -1, %4 ], [ 0, %9 ]
ret i32 %14
}