#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open_port();
int /*<<< orphan*/ set_uart_options(int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
main(int argc, char **argv) {
  int uart_fd;
  int n = 0, i;
  unsigned char command[12];
  if ((uart_fd = open_port()) == -1) {
    fprintf(stderr, "ERROR opening UART port\n");
  }
  set_uart_options(uart_fd);
  command[0] = 0xC1;
  command[1] = 5;
  command[2] = 32;
  command[3] = 0xC2;
  command[4] = 0;
  command[5] = 0;
  command[6] = 0xC3;
  command[7] = 0;
  command[8] = 0;
  command[9] = 0xC4;
  command[10] = 0;
  command[11] = 0;
  for (i = 0; i < 12; i++) {
    fprintf(stderr, "%u\n", command[i]);
  }
  n = write(uart_fd, command, 12);
  fprintf(stderr, "Wrote %d of 12 bytes\n", n);
  close(uart_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1070 <open_port@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1197 <main+0x47>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1030 <set_uart_options@plt>
movb   $0xc1,-0x28(%rbp)
movb   $0x5,-0x27(%rbp)
movb   $0x20,-0x26(%rbp)
movb   $0xc2,-0x25(%rbp)
movb   $0x0,-0x24(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0xc3,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
movb   $0x0,-0x20(%rbp)
movb   $0xc4,-0x1f(%rbp)
movb   $0x0,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xc,-0x1c(%rbp)
jge    120e <main+0xbe>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
movslq -0x1c(%rbp),%rax
movzbl -0x28(%rbp,%rax,1),%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d6 <main+0x86>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <open_port@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    117e <main+0x2e>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1030 <set_uart_options@plt>
movabs $0xc30000c22005c1,%rax
mov    %rax,0x4(%rsp)
movl   $0xc400,0xc(%rsp)
mov    0x2e3c(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe6b(%rip),%rbx
mov    %rbx,%rsi
mov    $0xc1,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x20,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0xc2,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0xc3,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0xc4,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1040 <write@plt>
mov    0x0(%rbp),%edi
lea    0xd90(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"ERROR opening UART port\0A\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [22 x i8] c"Wrote %d of 12 bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [12 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = call i32 (...) @open_port()
store i32 %10, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %6
%17 = call i32 @set_uart_options(i32 %16)
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
store i8 -63, i8* %18
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 1
store i8 5, i8* %19
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 2
store i8 32, i8* %20
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 3
store i8 -62, i8* %21
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 4
store i8 0, i8* %22
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 5
store i8 0, i8* %23
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 6
store i8 -61, i8* %24
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 7
store i8 0, i8* %25
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 8
store i8 0, i8* %26
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 9
store i8 -60, i8* %27
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 10
store i8 0, i8* %28
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 11
store i8 0, i8* %29
store i32 0, i32* %8
br label %30
30: ; preds = %41, %15
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 12
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %30
44: ; preds = %30
%45 = load i32, i32* %6
%46 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%47 = call i32 @write(i32 %45, i8* %46, i32 12)
store i32 %47, i32* %7
%48 = load i32, i32* @stderr
%49 = load i32, i32* %7
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"ERROR opening UART port\0A\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@.str.2 = [22 x i8] c"Wrote %d of 12 bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @open_port()
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = tail call i32 @set_uart_options(i32 %5)
store i8 -63, i8* %4
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 1
store i8 5, i8* %12
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 2
store i8 32, i8* %13
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 3
store i8 -62, i8* %14
%15 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 4
store i8 0, i8* %15
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 5
store i8 0, i8* %16
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 6
store i8 -61, i8* %17
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 7
store i8 0, i8* %18
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 8
store i8 0, i8* %19
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 9
store i8 -60, i8* %20
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 10
store i8 0, i8* %21
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 11
store i8 0, i8* %22
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 193)
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 5)
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 32)
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 194)
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 195)
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 196)
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%47 = call i32 @write(i32 %5, i8* %4, i32 12)
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%50 = tail call i32 @close(i32 %5)
ret i32 0
}