#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 /*<<< orphan*/ B115200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B230400;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ EINVAL;
int HUPCL;
int PARODD;
int /*<<< orphan*/ errno;
int commflags(int speed) {
  int i;
  const struct {
    int speed;
    int value;
  } r[] = {{2400, B2400},     {9600, B9600},   {19200, B19200},
           {38400, B38400},   {57600, B57600}, {115200, B115200},
           {230400, B230400}, {0, 0}};
  for (i = 0; r[i].speed != speed; i++)
    if (r[i].speed == 0) {
      errno = EINVAL;
      return -1;
    }
  return r[i].value | (PARODD | HUPCL | CS8 | CLOCAL | CREAD);
}


x86 assembly (clang, -O0):
<commflags>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x960,-0x50(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x2580,-0x48(%rbp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movl   $0x4b00,-0x40(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x9600,-0x38(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movl   $0xe100,-0x30(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1c200,-0x28(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x38400,-0x20(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%eax
cmp    -0x8(%rbp),%eax
je     11f2 <commflags+0xf2>
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,8)
jne    11df <commflags+0xdf>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd7(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <commflags+0x12c>
jmp    11e4 <commflags+0xe4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a1 <commflags+0xa1>
movslq -0xc(%rbp),%rax
mov    -0x4c(%rbp,%rax,8),%eax
mov    0x2ddf(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d86(%rip),%rdx
or     (%rdx),%ecx
mov    0x2db5(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d5c(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dab(%rip),%rdx
or     (%rdx),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<commflags>:
movl   $0x960,-0x48(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rsp)
movl   $0x2580,-0x40(%rsp)
mov    0x2eb4(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x3c(%rsp)
movl   $0x4b00,-0x38(%rsp)
mov    0x2eb7(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x34(%rsp)
movl   $0x9600,-0x30(%rsp)
mov    0x2e22(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x2c(%rsp)
movl   $0xe100,-0x28(%rsp)
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x24(%rsp)
movl   $0x1c200,-0x20(%rsp)
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x1c(%rsp)
movl   $0x38400,-0x18(%rsp)
mov    0x2df3(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x14(%rsp)
movq   $0x0,-0x10(%rsp)
cmp    $0x960,%edi
je     11c6 <commflags+0xc6>
mov    $0x960,%ecx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
test   %ecx,%ecx
je     11f5 <commflags+0xf5>
mov    -0x40(%rsp,%rax,8),%ecx
add    $0x1,%rax
cmp    %edi,%ecx
jne    11b0 <commflags+0xb0>
mov    %eax,%eax
mov    -0x44(%rsp,%rax,8),%eax
mov    0x2e13(%rip),%rcx
mov    0x2dbc(%rip),%rdx
mov    0x2ded(%rip),%rsi
mov    0x2d96(%rip),%rdi
mov    0x2de7(%rip),%r8
or     (%rcx),%eax
or     (%rdx),%eax
or     (%rsi),%eax
or     (%rdi),%eax
or     (%r8),%eax
ret
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    0x2da3(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.anon = type { i32, i32 }
@B2400 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@PARODD = global i32 0
@HUPCL = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
define i32 @commflags(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x %struct.anon]
store i32 %0, i32* %3
%6 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %5, i64 0, i64 0
%7 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 0
store i32 2400, i32* %7
%8 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 1
%9 = load i32, i32* @B2400
store i32 %9, i32* %8
%10 = getelementptr inbounds %struct.anon, %struct.anon* %6, i64 1
%11 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 0
store i32 9600, i32* %11
%12 = getelementptr inbounds %struct.anon, %struct.anon* %10, i32 0, i32 1
%13 = load i32, i32* @B9600
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.anon, %struct.anon* %10, i64 1
%15 = getelementptr inbounds %struct.anon, %struct.anon* %14, i32 0, i32 0
store i32 19200, i32* %15
%16 = getelementptr inbounds %struct.anon, %struct.anon* %14, i32 0, i32 1
%17 = load i32, i32* @B19200
store i32 %17, i32* %16
%18 = getelementptr inbounds %struct.anon, %struct.anon* %14, i64 1
%19 = getelementptr inbounds %struct.anon, %struct.anon* %18, i32 0, i32 0
store i32 38400, i32* %19
%20 = getelementptr inbounds %struct.anon, %struct.anon* %18, i32 0, i32 1
%21 = load i32, i32* @B38400
store i32 %21, i32* %20
%22 = getelementptr inbounds %struct.anon, %struct.anon* %18, i64 1
%23 = getelementptr inbounds %struct.anon, %struct.anon* %22, i32 0, i32 0
store i32 57600, i32* %23
%24 = getelementptr inbounds %struct.anon, %struct.anon* %22, i32 0, i32 1
%25 = load i32, i32* @B57600
store i32 %25, i32* %24
%26 = getelementptr inbounds %struct.anon, %struct.anon* %22, i64 1
%27 = getelementptr inbounds %struct.anon, %struct.anon* %26, i32 0, i32 0
store i32 115200, i32* %27
%28 = getelementptr inbounds %struct.anon, %struct.anon* %26, i32 0, i32 1
%29 = load i32, i32* @B115200
store i32 %29, i32* %28
%30 = getelementptr inbounds %struct.anon, %struct.anon* %26, i64 1
%31 = getelementptr inbounds %struct.anon, %struct.anon* %30, i32 0, i32 0
store i32 230400, i32* %31
%32 = getelementptr inbounds %struct.anon, %struct.anon* %30, i32 0, i32 1
%33 = load i32, i32* @B230400
store i32 %33, i32* %32
%34 = getelementptr inbounds %struct.anon, %struct.anon* %30, i64 1
%35 = getelementptr inbounds %struct.anon, %struct.anon* %34, i32 0, i32 0
store i32 0, i32* %35
%36 = getelementptr inbounds %struct.anon, %struct.anon* %34, i32 0, i32 1
store i32 0, i32* %36
store i32 0, i32* %4
br label %37
37: ; preds = %55, %1
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %5, i64 0, i64 %39
%41 = getelementptr inbounds %struct.anon, %struct.anon* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load i32, i32* %3
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %58
45: ; preds = %37
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %5, i64 0, i64 %47
%49 = getelementptr inbounds %struct.anon, %struct.anon* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = load i32, i32* @EINVAL
store i32 %53, i32* @errno
store i32 -1, i32* %2
br label %74
54: ; preds = %45
br label %55
55: ; preds = %54
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %37
58: ; preds = %37
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %5, i64 0, i64 %60
%62 = getelementptr inbounds %struct.anon, %struct.anon* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = load i32, i32* @PARODD
%65 = load i32, i32* @HUPCL
%66 = or i32 %64, %65
%67 = load i32, i32* @CS8
%68 = or i32 %66, %67
%69 = load i32, i32* @CLOCAL
%70 = or i32 %68, %69
%71 = load i32, i32* @CREAD
%72 = or i32 %70, %71
%73 = or i32 %63, %72
store i32 %73, i32* %2
br label %74
74: ; preds = %58, %52
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
%struct.anon = type { i32, i32 }
@B2400 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@PARODD = global i32 0
@HUPCL = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
define i32 @commflags(i32 %0) {
%2 = alloca [8 x %struct.anon]
%3 = bitcast [8 x %struct.anon]* %2 to i8*
%4 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 0, i32 0
store i32 2400, i32* %4
%5 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 0, i32 1
%6 = load i32, i32* @B2400
store i32 %6, i32* %5
%7 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 1, i32 0
store i32 9600, i32* %7
%8 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 1, i32 1
%9 = load i32, i32* @B9600
store i32 %9, i32* %8
%10 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 2, i32 0
store i32 19200, i32* %10
%11 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 2, i32 1
%12 = load i32, i32* @B19200
store i32 %12, i32* %11
%13 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 3, i32 0
store i32 38400, i32* %13
%14 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 3, i32 1
%15 = load i32, i32* @B38400
store i32 %15, i32* %14
%16 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 4, i32 0
store i32 57600, i32* %16
%17 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 4, i32 1
%18 = load i32, i32* @B57600
store i32 %18, i32* %17
%19 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 5, i32 0
store i32 115200, i32* %19
%20 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 5, i32 1
%21 = load i32, i32* @B115200
store i32 %21, i32* %20
%22 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 6, i32 0
store i32 230400, i32* %22
%23 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 6, i32 1
%24 = load i32, i32* @B230400
store i32 %24, i32* %23
%25 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 7, i32 0
store i32 0, i32* %25
%26 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 7, i32 1
store i32 0, i32* %26
%27 = icmp eq i32 %0, 2400
br i1 %27, label %43, label %28
28: ; preds = %1, %34
%29 = phi i64 [ %35, %34 ], [ 0, %1 ]
%30 = phi i32 [ %37, %34 ], [ 2400, %1 ]
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i32, i32* @EINVAL
store i32 %33, i32* @errno
br label %55
34: ; preds = %28
%35 = add nuw i64 %29, 1
%36 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 %35, i32 0
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, %0
br i1 %38, label %39, label %28
39: ; preds = %34
%40 = and i64 %35, 4294967295
%41 = getelementptr inbounds [8 x %struct.anon], [8 x %struct.anon]* %2, i64 0, i64 %40, i32 1
%42 = load i32, i32* %41
br label %43
43: ; preds = %1, %39
%44 = phi i32 [ %42, %39 ], [ %6, %1 ]
%45 = load i32, i32* @PARODD
%46 = load i32, i32* @HUPCL
%47 = load i32, i32* @CS8
%48 = load i32, i32* @CLOCAL
%49 = load i32, i32* @CREAD
%50 = or i32 %45, %44
%51 = or i32 %50, %46
%52 = or i32 %51, %47
%53 = or i32 %52, %48
%54 = or i32 %53, %49
br label %55
55: ; preds = %43, %32
%56 = phi i32 [ -1, %32 ], [ %54, %43 ]
ret i32 %56
}