#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 SioCmdportFd(int);
int SioWaitAck(int, unsigned char);
unsigned short ntohs(int);
int write(int, unsigned char *, int);
int sio_break(int fd, int time) {
  unsigned char buf[8];
  if ((fd = SioCmdportFd(fd)) == -1)
    return (-1);
  buf[0] = 35;
  buf[1] = 2;
  *(unsigned short *)&buf[2] = ntohs(time);
  if (write(fd, buf, 4) != 4)
    return (-1);
  return (SioWaitAck(fd, buf[0]));
}


x86 assembly (clang, -O0):
<sio_break>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <SioCmdportFd@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    116e <sio_break+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <sio_break+0x77>
movb   $0x23,-0x14(%rbp)
movb   $0x2,-0x13(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <ntohs@plt>
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
je     11a8 <sio_break+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <sio_break+0x77>
mov    -0x8(%rbp),%edi
movzbl -0x14(%rbp),%esi
call   1040 <SioWaitAck@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_break>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1060 <SioCmdportFd@plt>
cmp    $0xffffffff,%eax
je     1189 <sio_break+0x49>
mov    %eax,%ebx
movw   $0x223,(%rsp)
mov    %ebp,%edi
call   1050 <ntohs@plt>
mov    %ax,0x2(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1189 <sio_break+0x49>
mov    %ebx,%edi
mov    $0x23,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <SioWaitAck@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sio_break(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i32 @SioCmdportFd(i32 %7)
store i32 %8, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %28
11: ; preds = %2
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
store i8 35, i8* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
store i8 2, i8* %13
%14 = load i32, i32* %5
%15 = call zeroext i16 @ntohs(i32 %14)
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
%17 = bitcast i8* %16 to i16*
store i16 %15, i16* %17
%18 = load i32, i32* %4
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 4)
%21 = icmp ne i32 %20, 4
br i1 %21, label %22, label %23
22: ; preds = %11
store i32 -1, i32* %3
br label %28
23: ; preds = %11
%24 = load i32, i32* %4
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%26 = load i8, i8* %25
%27 = call i32 @SioWaitAck(i32 %24, i8 zeroext %26)
store i32 %27, i32* %3
br label %28
28: ; preds = %23, %22, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @sio_break(i32 %0, i32 %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @SioCmdportFd(i32 %0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %16, label %7
7: ; preds = %2
store i8 35, i8* %4
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
store i8 2, i8* %8
%9 = tail call zeroext i16 @ntohs(i32 %1)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%11 = bitcast i8* %10 to i16*
store i16 %9, i16* %11
%12 = call i32 @write(i32 %5, i8* %4, i32 4)
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @SioWaitAck(i32 %5, i8 zeroext 35)
br label %16
16: ; preds = %7, %2, %14
%17 = phi i32 [ %15, %14 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %17
}