#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*/ ByteToHexStr(char *, char *, int);
int InitSerial();
int /*<<< orphan*/ UART_Send(int, char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  int u;
  u = InitSerial();
  if (u == -1) {
    fprintf(stderr, "InitSerial Error!\n");
    return -1;
  }
  char *buffer = (char *)malloc(8 * sizeof(char));
  *buffer = 0xff;
  *(buffer + 1) = 0xff;
  *(buffer + 2) = 0xfe;
  *(buffer + 3) = 0x04;
  *(buffer + 4) = 0x03;
  *(buffer + 5) = 0x04;
  *(buffer + 6) = 0x01;
  int sum;
  sum = 0xfe;
  sum += 0x04;
  sum += 0x03;
  sum += 0x04 + 1;
  sum = sum & 0xff;
  sum = ~sum;
  char *chsum = (char *)malloc(sizeof(char));
  memcpy(chsum, &sum, sizeof(char));
  *(buffer + 7) = *chsum;
  char todisplay[50];
  char *p_display = todisplay;
  memset(p_display, 0, 50 * sizeof(char));
  ByteToHexStr(buffer, p_display, 8 * sizeof(char));
  printf("Sending:\n %s \n", p_display);
  UART_Send(u, buffer, 8 * sizeof(char));
  free(buffer);
  close(u);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10c0 <InitSerial@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e4 <main+0x44>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <main+0x148>
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0xfe,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x4,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x3,0x4(%rax)
mov    -0x10(%rbp),%rax
movb   $0x4,0x5(%rax)
mov    -0x10(%rbp),%rax
movb   $0x1,0x6(%rax)
movl   $0xfe,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1090 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x7(%rax)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x8,%edx
call   1040 <ByteToHexStr@plt>
mov    -0x68(%rbp),%rsi
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   10b0 <UART_Send@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   10c0 <InitSerial@plt>
cmp    $0xffffffff,%eax
je     125f <main+0xbf>
mov    %eax,%r15d
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
movl   $0x4feffff,(%rax)
movw   $0x403,0x4(%rax)
movb   $0x1,0x6(%rax)
movl   $0xfffffff5,0xc(%rsp)
ff
mov    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
call   1090 <memcpy@plt>
mov    0x0(%rbp),%al
mov    %al,0x7(%rbx)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <ByteToHexStr@plt>
lea    0xdde(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10b0 <UART_Send@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1070 <close@plt>
jmp    127a <main+0xda>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"InitSerial Error!\0A\00"
@.str.1 = [15 x i8] c"Sending:\0A %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [50 x i8]
%7 = alloca i8*
store i32 0, i32* %1
%8 = call i32 (...) @InitSerial()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
14: ; preds = %0
%15 = call i64 @malloc(i32 8)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %3
%17 = load i8*, i8** %3
store i8 -1, i8* %17
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 -1, i8* %19
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8 -2, i8* %21
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 3
store i8 4, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 4
store i8 3, i8* %25
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 5
store i8 4, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 6
store i8 1, i8* %29
store i32 254, i32* %4
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 4
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 3
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 5
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = and i32 %36, 255
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = xor i32 %38, -1
store i32 %39, i32* %4
%40 = call i64 @malloc(i32 1)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %5
%42 = load i8*, i8** %5
%43 = call i32 @memcpy(i8* %42, i32* %4, i32 1)
%44 = load i8*, i8** %5
%45 = load i8, i8* %44
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 7
store i8 %45, i8* %47
%48 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = call i32 @memset(i8* %49, i32 0, i32 50)
%51 = load i8*, i8** %3
%52 = load i8*, i8** %7
%53 = call i32 @ByteToHexStr(i8* %51, i8* %52, i32 8)
%54 = load i8*, i8** %7
%55 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %2
%57 = load i8*, i8** %3
%58 = call i32 @UART_Send(i32 %56, i8* %57, i32 8)
%59 = load i8*, i8** %3
%60 = call i32 @free(i8* %59)
%61 = load i32, i32* %2
%62 = call i32 @close(i32 %61)
br label %63
63: ; preds = %14, %11
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"InitSerial Error!\0A\00"
@.str.1 = [15 x i8] c"Sending:\0A %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = tail call i32 (...) @InitSerial()
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %30
8: ; preds = %0
%9 = tail call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to i8*
store i8 -1, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 -1, i8* %11
%12 = getelementptr inbounds i8, i8* %10, i64 2
store i8 -2, i8* %12
%13 = getelementptr inbounds i8, i8* %10, i64 3
store i8 4, i8* %13
%14 = getelementptr inbounds i8, i8* %10, i64 4
store i8 3, i8* %14
%15 = getelementptr inbounds i8, i8* %10, i64 5
store i8 4, i8* %15
%16 = getelementptr inbounds i8, i8* %10, i64 6
store i8 1, i8* %16
%17 = bitcast i32* %1 to i8*
store i32 -11, i32* %1
%18 = tail call i64 @malloc(i32 1)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @memcpy(i8* %19, i32* %1, i32 1)
%21 = load i8, i8* %19
%22 = getelementptr inbounds i8, i8* %10, i64 7
store i8 %21, i8* %22
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 50)
%25 = call i32 @ByteToHexStr(i8* %10, i8* %23, i32 8)
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%27 = call i32 @UART_Send(i32 %3, i8* %10, i32 8)
%28 = call i32 @free(i8* %10)
%29 = call i32 @close(i32 %3)
br label %30
30: ; preds = %8, %5
%31 = phi i32 [ -1, %5 ], [ 0, %8 ]
ret i32 %31
}