#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 */
unsigned int CBAUD;
int EXIT_FAILURE;
int ioctl(int, int, unsigned int *);
int /*<<< orphan*/ perror(char *);
unsigned _set_special_baudrate(int fd, unsigned baud) {
  unsigned buf[64];
  int r;
  r = ioctl(fd, 0x802C542A, buf);
  if (r) {
    perror("TCGETS2");
    return EXIT_FAILURE;
  }
  buf[2] &= ~CBAUD;
  buf[2] |= 010000;
  buf[9] = buf[10] = baud;
  r = ioctl(fd, 0x402C542B, buf);
  if (r) {
    perror("TCSETS2");
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<_set_special_baudrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rdx
mov    $0x802c542a,%esi
call   1030 <ioctl@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     1175 <_set_special_baudrate+0x55>
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <_set_special_baudrate+0xcc>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x108(%rbp),%eax
mov    %eax,-0x108(%rbp)
mov    -0x108(%rbp),%eax
or     $0x1000,%eax
mov    %eax,-0x108(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0xe8(%rbp)
mov    %eax,-0xec(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rdx
mov    $0x402c542b,%esi
call   1030 <ioctl@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     11ec <_set_special_baudrate+0xcc>
lea    0xe2d(%rip),%rdi
call   1040 <perror@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_set_special_baudrate>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdx
mov    $0x802c542a,%esi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    117d <_set_special_baudrate+0x5d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
or     $0x1000,%eax
mov    %eax,0x8(%rsp)
mov    %ebp,0x28(%rsp)
mov    %ebp,0x24(%rsp)
mov    %rsp,%rdx
mov    %ebx,%edi
mov    $0x402c542b,%esi
call   1030 <ioctl@plt>
mov    %eax,%ecx
test   %ecx,%ecx
jne    1186 <_set_special_baudrate+0x66>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7c(%rip),%rdi
jmp    118d <_set_special_baudrate+0x6d>
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
jmp    1173 <_set_special_baudrate+0x53>

LLVM IR (-O0):
@.str = [8 x i8] c"TCGETS2\00"
@EXIT_FAILURE = global i32 0
@CBAUD = global i32 0
@.str.1 = [8 x i8] c"TCSETS2\00"
define i32 @_set_special_baudrate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [64 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%10 = call i32 @ioctl(i32 %8, i32 -2144578518, i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %36
16: ; preds = %2
%17 = load i32, i32* @CBAUD
%18 = xor i32 %17, -1
%19 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 2
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 2
%23 = load i32, i32* %22
%24 = or i32 %23, 4096
store i32 %24, i32* %22
%25 = load i32, i32* %5
%26 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 10
store i32 %25, i32* %26
%27 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 9
store i32 %25, i32* %27
%28 = load i32, i32* %4
%29 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%30 = call i32 @ioctl(i32 %28, i32 1076646955, i32* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %16
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %36
36: ; preds = %13, %33, %16
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [8 x i8] c"TCGETS2\00"
@EXIT_FAILURE = global i32 0
@CBAUD = global i32 0
@.str.1 = [8 x i8] c"TCSETS2\00"
define i32 @_set_special_baudrate(i32 %0, i32 %1) {
%3 = alloca [64 x i32]
%4 = bitcast [64 x i32]* %3 to i8*
%5 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 0
%6 = call i32 @ioctl(i32 %0, i32 -2144578518, i32* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i32, i32* @CBAUD
%10 = xor i32 %9, -1
%11 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 2
%12 = load i32, i32* %11
%13 = and i32 %12, %10
%14 = or i32 %13, 4096
store i32 %14, i32* %11
%15 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 10
store i32 %1, i32* %15
%16 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 9
store i32 %1, i32* %16
%17 = call i32 @ioctl(i32 %0, i32 1076646955, i32* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %8, %2
%20 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %8 ]
%21 = call i32 @perror(i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
br label %23
23: ; preds = %19, %8
%24 = phi i32 [ undef, %8 ], [ %22, %19 ]
ret i32 %24
}