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


x86 assembly (clang, -O0):
<sio_baud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <SioCmdportFd@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    115f <sio_baud+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <sio_baud+0x74>
movb   $0x17,-0x18(%rbp)
movb   $0x4,-0x17(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x16(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
je     1195 <sio_baud+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <sio_baud+0x74>
mov    -0x8(%rbp),%edi
movzbl -0x18(%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_baud>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1050 <SioCmdportFd@plt>
cmp    $0xffffffff,%eax
je     116f <sio_baud+0x3f>
mov    %eax,%ebx
mov    %r14,0x2(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
jne    116f <sio_baud+0x3f>
mov    %ebx,%edi
mov    $0x17,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <SioWaitAck@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @sio_baud(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [8 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %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 [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 i64, i64* %5
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
%16 = bitcast i8* %15 to i64*
store i64 %14, i64* %16
%17 = load i32, i32* %4
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 6)
%20 = icmp ne i32 %19, 6
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 [8 x i8], [8 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_baud(i32 %0, i64 %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 %14, label %7
7: ; preds = %2
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%9 = bitcast i8* %8 to i64*
store i64 %1, i64* %9
%10 = call i32 @write(i32 %5, i8* %4, i32 6)
%11 = icmp eq i32 %10, 6
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @SioWaitAck(i32 %5, i8 zeroext 23)
br label %14
14: ; preds = %7, %2, %12
%15 = phi i32 [ %13, %12 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %15
}