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


x86 assembly (clang, -O0):
<sio_flush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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_flush+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <sio_flush+0x71>
movb   $0x14,-0x10(%rbp)
movb   $0x1,-0xf(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     1192 <sio_flush+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <sio_flush+0x71>
mov    -0x8(%rbp),%edi
movzbl -0x10(%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_flush>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1050 <SioCmdportFd@plt>
cmp    $0xffffffff,%eax
je     1175 <sio_flush+0x45>
mov    %eax,%ebx
movw   $0x114,0x4(%rsp)
mov    %bpl,0x6(%rsp)
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
jne    1175 <sio_flush+0x45>
mov    %ebx,%edi
mov    $0x14,%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_flush(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 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 %27
11: ; preds = %2
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 20, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 1, i8* %13
%14 = load i32, i32* %5
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
store i8 %15, i8* %16
%17 = load i32, i32* %4
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 3)
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 -1, i32* %3
br label %27
22: ; preds = %11
%23 = load i32, i32* %4
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%25 = load i8, i8* %24
%26 = call i32 @SioWaitAck(i32 %23, i8 zeroext %25)
store i32 %26, i32* %3
br label %27
27: ; preds = %22, %21, %10
%28 = load i32, i32* %3
ret i32 %28
}

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