#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);
int write(int, unsigned char *, int);
int sio_iqueue(int fd) {
  unsigned char buf[4];
  if ((fd = SioCmdportFd(fd)) == -1)
    return (-1);
  buf[0] = 21;
  buf[1] = 0;
  if (write(fd, buf, 2) != 2)
    return (-1);
  return (SioWaitAck(fd, buf[0]));
}


x86 assembly (clang, -O0):
<sio_iqueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <SioCmdportFd@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    115b <sio_iqueue+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <sio_iqueue+0x68>
movb   $0x15,-0xc(%rbp)
movb   $0x0,-0xb(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1189 <sio_iqueue+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <sio_iqueue+0x68>
mov    -0x8(%rbp),%edi
movzbl -0xc(%rbp),%esi
call   1040 <SioWaitAck@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_iqueue>:
push   %rbx
sub    $0x10,%rsp
call   1050 <SioCmdportFd@plt>
cmp    $0xffffffff,%eax
je     116f <sio_iqueue+0x3f>
mov    %eax,%ebx
movw   $0x15,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    116f <sio_iqueue+0x3f>
mov    %ebx,%edi
mov    $0x15,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <SioWaitAck@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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