#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 */
struct termios {
  int dummy;
};
typedef scalar_t__ speed_t;

/* Variables and functions */
int /*<<< orphan*/ B9600;
scalar_t__ cfgetispeed(struct termios *);
scalar_t__ cfgetospeed(struct termios *);
scalar_t__ cfsetispeed(struct termios *, int /*<<< orphan*/);
scalar_t__ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, scalar_t__, ...);
char *strerror(int /*<<< orphan*/);
int setBaudRate(int fd, struct termios config) {
  speed_t speedin = cfgetispeed(&config);
  if (speedin < 0) {
    printf("setBaudRate: %s\n", strerror(errno));
  }
  speed_t speedout = cfgetospeed(&config);
  if (speedout < 0) {
    printf("setBaudRate: %s\n", strerror(errno));
  }
  if (speedin != speedout) {
    printf("Speed difference:\n\tin = %i\n\tout = %i\n", speedin, speedout);
  }
  speedin = cfsetispeed(&config, B9600);
  if (speedin < 0) {
    printf("set in error: %s\n", strerror(errno));
  }
  speedout = cfsetospeed(&config, B9600);
  if (speedout < 0) {
    printf("set out error: %s\n", strerror(errno));
  }
  if (speedin != speedout) {
    printf("Speed difference:\n\tin = %i\n\tout = %i\n", speedin, speedout);
    return -1;
  } else {
    return speedin;
  }
}


x86 assembly (clang, -O0):
<setBaudRate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <cfgetispeed@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11a5 <setBaudRate+0x45>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1060 <cfgetospeed@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11dc <setBaudRate+0x7c>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1200 <setBaudRate+0xa0>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1240 <setBaudRate+0xe0>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1280 <setBaudRate+0x120>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12b0 <setBaudRate+0x150>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <setBaudRate+0x157>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setBaudRate>:
push   %r14
push   %rbx
push   %rax
mov    %esi,(%rsp)
mov    %rsp,%rdi
call   1030 <cfgetispeed@plt>
mov    %rax,%r14
test   %rax,%rax
jns    1196 <setBaudRate+0x36>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe74(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1060 <cfgetospeed@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1237 <setBaudRate+0xd7>
cmp    %rbx,%r14
je     11c3 <setBaudRate+0x63>
lea    0xe5b(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e1e(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdi
call   1070 <cfsetispeed@plt>
mov    %rax,%r14
test   %rax,%rax
jns    11fb <setBaudRate+0x9b>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
mov    %rsp,%rdi
call   1040 <cfsetospeed@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1264 <setBaudRate+0x104>
cmp    %rbx,%r14
je     122c <setBaudRate+0xcc>
lea    0xdf8(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdb4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbx,%r14
jne    11af <setBaudRate+0x4f>
jmp    11c3 <setBaudRate+0x63>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdd0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbx,%r14
jne    1212 <setBaudRate+0xb2>
jmp    122c <setBaudRate+0xcc>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [17 x i8] c"setBaudRate: %s\0A\00"
@errno = global i32 0
@.str.1 = [38 x i8] c"Speed difference:\0A\09in = %i\0A\09out = %i\0A\00"
@B9600 = global i32 0
@.str.2 = [18 x i8] c"set in error: %s\0A\00"
@.str.3 = [19 x i8] c"set out error: %s\0A\00"
define i32 @setBaudRate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.termios
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
store i32 %1, i32* %8
store i32 %0, i32* %5
%9 = call i64 @cfgetispeed(%struct.termios* %4)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = ptrtoint i8* %14 to i64
%16 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %17
17: ; preds = %12, %2
%18 = call i64 @cfgetospeed(%struct.termios* %4)
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = ptrtoint i8* %23 to i64
%25 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %21, %17
%27 = load i64, i64* %6
%28 = load i64, i64* %7
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %31, i64 %32)
br label %34
34: ; preds = %30, %26
%35 = load i32, i32* @B9600
%36 = call i64 @cfsetispeed(%struct.termios* %4, i32 %35)
store i64 %36, i64* %6
%37 = load i64, i64* %6
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = ptrtoint i8* %41 to i64
%43 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %39, %34
%45 = load i32, i32* @B9600
%46 = call i64 @cfsetospeed(%struct.termios* %4, i32 %45)
store i64 %46, i64* %7
%47 = load i64, i64* %7
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = ptrtoint i8* %51 to i64
%53 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %52)
br label %54
54: ; preds = %49, %44
%55 = load i64, i64* %6
%56 = load i64, i64* %7
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load i64, i64* %6
%60 = load i64, i64* %7
%61 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %59, i64 %60)
store i32 -1, i32* %3
br label %65
62: ; preds = %54
%63 = load i64, i64* %6
%64 = trunc i64 %63 to i32
store i32 %64, i32* %3
br label %65
65: ; preds = %62, %58
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [17 x i8] c"setBaudRate: %s\0A\00"
@errno = global i32 0
@.str.1 = [38 x i8] c"Speed difference:\0A\09in = %i\0A\09out = %i\0A\00"
@B9600 = global i32 0
@.str.2 = [18 x i8] c"set in error: %s\0A\00"
@.str.3 = [19 x i8] c"set out error: %s\0A\00"
define i32 @setBaudRate(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %1, i32* %4
%5 = call i64 @cfgetispeed(%struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = ptrtoint i8* %9 to i64
%11 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %12
12: ; preds = %7, %2
%13 = call i64 @cfgetospeed(%struct.termios* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = ptrtoint i8* %17 to i64
%19 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %15, %12
%21 = icmp eq i64 %5, %13
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %5, i64 %13)
br label %24
24: ; preds = %22, %20
%25 = load i32, i32* @B9600
%26 = call i64 @cfsetispeed(%struct.termios* %3, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = ptrtoint i8* %30 to i64
%32 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %31)
br label %33
33: ; preds = %28, %24
%34 = load i32, i32* @B9600
%35 = call i64 @cfsetospeed(%struct.termios* %3, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = ptrtoint i8* %39 to i64
%41 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %37, %33
%43 = icmp eq i64 %26, %35
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %26, i64 %35)
br label %48
46: ; preds = %42
%47 = trunc i64 %26 to i32
br label %48
48: ; preds = %46, %44
%49 = phi i32 [ -1, %44 ], [ %47, %46 ]
ret i32 %49
}