#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 O_NOCTTY;
int O_RDWR;
int O_SYNC;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_blocking(int, int /*<<< orphan*/);
int /*<<< orphan*/ set_interface_attribs(int, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ write(int, char *, int);
void main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "error: syntax %s <port>", argv[0]);
    exit(1);
  }
  char *portname = argv[1];
  int fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
  if (fd < 0) {
    fprintf(stderr, "error %d opening %s: %s", errno, portname,
            strerror(errno));
    return;
  }
  set_interface_attribs(fd, B115200, 0);
  set_blocking(fd, 0);
  printf("Sending beacon in loop. You have 5-10 seconds to power up Omnia.\n");
  char buf[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xbb};
  int i;
  for (i = 0; i < 10000; i++)
    write(fd, buf, 8);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    11d1 <main+0x41>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
mov    0x2de6(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125c <main+0xcc>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12cb <main+0x13b>
mov    -0x1c(%rbp),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <set_interface_attribs@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1060 <set_blocking@plt>
lea    0xdb0(%rip),%rdi
call   1050 <printf@plt>
mov    0xde6(%rip),%rax
mov    %rax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2710,-0x28(%rbp)
jge    12c3 <main+0x133>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1297 <main+0x107>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    126c <main+0xdc>
mov    0x2e40(%rip),%rcx
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%r14
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    %r14,%rdi
mov    %eax,%esi
call   1090 <open@plt>
test   %eax,%eax
js     1233 <main+0xa3>
mov    %eax,%ebx
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <set_interface_attribs@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <set_blocking@plt>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
movabs $0xbb77665544332211,%rax
66 77 bb
mov    %rax,0x8(%rsp)
mov    $0x2710,%ebp
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
jne    1210 <main+0x80>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <close@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xdc5(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <fprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd81(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"error: syntax %s <port>\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [24 x i8] c"error %d opening %s: %s\00"
@errno = global i32 0
@B115200 = global i32 0
@.str.2 = [66 x i8] c"Sending beacon in loop. You have 5-10 seconds to power up Omnia.\0A\00"
@__const.main.buf = [8 x i8] c"\11\223DUfw\BB"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [8 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_NOCTTY
%25 = or i32 %23, %24
%26 = load i32, i32* @O_SYNC
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %22, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = load i8*, i8** %5
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %34, i8* %36)
br label %59
38: ; preds = %18
%39 = load i32, i32* %6
%40 = load i32, i32* @B115200
%41 = call i32 @set_interface_attribs(i32 %39, i32 %40, i32 0)
%42 = load i32, i32* %6
%43 = call i32 @set_blocking(i32 %42, i32 0)
%44 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%45 = bitcast [8 x i8]* %7 to i8*
store i32 0, i32* %8
br label %46
46: ; preds = %53, %38
%47 = load i32, i32* %8
%48 = icmp slt i32 %47, 10000
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i32, i32* %6
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%52 = call i32 @write(i32 %50, i8* %51, i32 8)
br label %53
53: ; preds = %49
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %46
56: ; preds = %46
%57 = load i32, i32* %6
%58 = call i32 @close(i32 %57)
br label %59
59: ; preds = %56, %31
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"error: syntax %s <port>\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [24 x i8] c"error %d opening %s: %s\00"
@errno = global i32 0
@B115200 = global i32 0
@str = [65 x i8] c"Sending beacon in loop. You have 5-10 seconds to power up Omnia.\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NOCTTY
%15 = or i32 %14, %13
%16 = load i32, i32* @O_SYNC
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* %12, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %12, i8* %23)
br label %38
25: ; preds = %10
%26 = load i32, i32* @B115200
%27 = tail call i32 @set_interface_attribs(i32 %18, i32 %26, i32 0)
%28 = tail call i32 @set_blocking(i32 %18, i32 0)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%30 = bitcast i64* %3 to i8*
store i64 -4938365949986004463, i64* %3
br label %31
31: ; preds = %25, %31
%32 = phi i32 [ 0, %25 ], [ %34, %31 ]
%33 = call i32 @write(i32 %18, i8* %30, i32 8)
%34 = add nuw nsw i32 %32, 1
%35 = icmp eq i32 %34, 10000
br i1 %35, label %36, label %31
36: ; preds = %31
%37 = tail call i32 @close(i32 %18)
br label %38
38: ; preds = %36, %20
ret void
}