#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_flowctrl(int fd, int mode) {
  unsigned char buf[8];
  if ((fd = SioCmdportFd(fd)) == -1)
    return (-1);
  buf[0] = 23;
  buf[1] = 4;
  if (mode & 1)
    buf[2] = 1;
  else
    buf[2] = 0;
  if (mode & 2)
    buf[3] = 1;
  else
    buf[3] = 0;
  if (mode & 4)
    buf[4] = 1;
  else
    buf[4] = 0;
  if (mode & 8)
    buf[5] = 1;
  else
    buf[5] = 0;
  if (write(fd, buf, 6) != 6)
    return (-1);
  return (SioWaitAck(fd, buf[0]));
}


x86 assembly (clang, -O0):
<sio_flowctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <SioCmdportFd@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    115e <sio_flowctrl+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <sio_flowctrl+0xdb>
movb   $0x17,-0x14(%rbp)
movb   $0x4,-0x13(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117e <sio_flowctrl+0x4e>
movb   $0x1,-0x12(%rbp)
jmp    1182 <sio_flowctrl+0x52>
movb   $0x0,-0x12(%rbp)
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     119a <sio_flowctrl+0x6a>
movb   $0x1,-0x11(%rbp)
jmp    119e <sio_flowctrl+0x6e>
movb   $0x0,-0x11(%rbp)
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11b6 <sio_flowctrl+0x86>
movb   $0x1,-0x10(%rbp)
jmp    11ba <sio_flowctrl+0x8a>
movb   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11d2 <sio_flowctrl+0xa2>
movb   $0x1,-0xf(%rbp)
jmp    11d6 <sio_flowctrl+0xa6>
movb   $0x0,-0xf(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
je     11fc <sio_flowctrl+0xcc>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <sio_flowctrl+0xdb>
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_flowctrl>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1050 <SioCmdportFd@plt>
cmp    $0xffffffff,%eax
je     1197 <sio_flowctrl+0x67>
mov    %eax,%ebx
movw   $0x417,(%rsp)
mov    %ebp,%eax
and    $0x1,%al
mov    %al,0x2(%rsp)
mov    %ebp,%eax
shr    %al
and    $0x1,%al
mov    %al,0x3(%rsp)
mov    %ebp,%eax
shr    $0x2,%al
and    $0x1,%al
mov    %al,0x4(%rsp)
shr    $0x3,%bpl
and    $0x1,%bpl
mov    %bpl,0x5(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
jne    1197 <sio_flowctrl+0x67>
mov    %ebx,%edi
mov    $0x17,%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_flowctrl(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 %56
11: ; preds = %2
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
store i8 23, i8* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
store i8 4, i8* %13
%14 = load i32, i32* %5
%15 = and i32 %14, 1
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
store i8 1, i8* %18
br label %21
19: ; preds = %11
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
store i8 0, i8* %20
br label %21
21: ; preds = %19, %17
%22 = load i32, i32* %5
%23 = and i32 %22, 2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
store i8 1, i8* %26
br label %29
27: ; preds = %21
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
store i8 0, i8* %28
br label %29
29: ; preds = %27, %25
%30 = load i32, i32* %5
%31 = and i32 %30, 4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
store i8 1, i8* %34
br label %37
35: ; preds = %29
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
store i8 0, i8* %36
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* %5
%39 = and i32 %38, 8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
store i8 1, i8* %42
br label %45
43: ; preds = %37
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
store i8 0, i8* %44
br label %45
45: ; preds = %43, %41
%46 = load i32, i32* %4
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%48 = call i32 @write(i32 %46, i8* %47, i32 6)
%49 = icmp ne i32 %48, 6
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 -1, i32* %3
br label %56
51: ; preds = %45
%52 = load i32, i32* %4
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%54 = load i8, i8* %53
%55 = call i32 @SioWaitAck(i32 %52, i8 zeroext %54)
store i32 %55, i32* %3
br label %56
56: ; preds = %51, %50, %10
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @sio_flowctrl(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 %28, label %7
7: ; preds = %2
store i8 23, i8* %4
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
store i8 4, i8* %8
%9 = trunc i32 %1 to i8
%10 = and i8 %9, 1
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
store i8 %10, i8* %11
%12 = trunc i32 %1 to i8
%13 = lshr i8 %12, 1
%14 = and i8 %13, 1
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
store i8 %14, i8* %15
%16 = trunc i32 %1 to i8
%17 = lshr i8 %16, 2
%18 = and i8 %17, 1
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 %18, i8* %19
%20 = trunc i32 %1 to i8
%21 = lshr i8 %20, 3
%22 = and i8 %21, 1
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 %22, i8* %23
%24 = call i32 @write(i32 %5, i8* %4, i32 6)
%25 = icmp eq i32 %24, 6
br i1 %25, label %26, label %28
26: ; preds = %7
%27 = tail call i32 @SioWaitAck(i32 %5, i8 zeroext 23)
br label %28
28: ; preds = %7, %2, %26
%29 = phi i32 [ %27, %26 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %29
}