#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*/ fflush(int /*<<< orphan*/);
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*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main() {
  int u;
  u = InitSerial();
  if (u == -1) {
    fprintf(stderr, "InitSerial Error!\n");
    return -1;
  }
  int input;
  scanf("%d", &input);
  if (input < 253) {
    input &= 0xff;
    unsigned char *inputID = (char *)&input;
    char *buffer = (char *)malloc(11 * sizeof(char));
    *buffer = 0xff;
    *(buffer + 1) = 0xff;
    *(buffer + 2) = *inputID;
    *(buffer + 3) = 0x07;
    *(buffer + 4) = 0x03;
    *(buffer + 5) = 0x1e;
    *(buffer + 6) = 0x00;
    *(buffer + 7) = 0x02;
    *(buffer + 8) = 0x00;
    *(buffer + 9) = 0x02;
    int sum;
    sum = *inputID;
    sum += 0x07;
    sum += 0x03 + 0x1e;
    sum += 0x04;
    sum = sum & 0xff;
    sum = ~sum;
    char *chsum = (char *)malloc(sizeof(char));
    memcpy(chsum, &sum, sizeof(char));
    *(buffer + 10) = *chsum;
    char todisplay[50];
    char *p_display = todisplay;
    memset(p_display, 0, 50 * sizeof(char));
    ByteToHexStr(buffer, p_display, 11 * sizeof(char));
    printf("Sending:\n %s \n", p_display);
    UART_Send(u, buffer, 11 * sizeof(char));
    free(buffer);
    free(chsum);
  } else {
    fflush(stdin);
    fprintf(stderr, "Error:inputID cannot large than 253.\n");
  }
  close(u);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10e0 <InitSerial@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1207 <main+0x47>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138c <main+0x1cc>
lea    0xe05(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10c0 <scanf@plt>
cmpl   $0xfd,-0xc(%rbp)
jge    1361 <main+0x1a1>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0xb,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x20(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x7,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0x3,0x4(%rax)
mov    -0x20(%rbp),%rax
movb   $0x1e,0x5(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x20(%rbp),%rax
movb   $0x2,0x7(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rax
movb   $0x2,0x9(%rax)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x21,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x1,%edx
call   1090 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0xa(%rax)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    $0xb,%edx
call   1040 <ByteToHexStr@plt>
mov    -0x78(%rbp),%rsi
lea    0xce2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0xb,%edx
call   10d0 <UART_Send@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1384 <main+0x1c4>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xca6(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %eax,%eax
call   10e0 <InitSerial@plt>
cmp    $0xffffffff,%eax
je     12b1 <main+0xf1>
mov    %eax,%ebp
lea    0xe30(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10c0 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    $0xfc,%eax
jg     12cd <main+0x10d>
movzbl %al,%eax
mov    %eax,0x8(%rsp)
mov    $0xb,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
movw   $0xffff,(%rax)
mov    0x8(%rsp),%al
mov    %al,0x2(%rbx)
movl   $0x1e0307,0x3(%rbx)
movw   $0x2,0x7(%rbx)
movb   $0x2,0x9(%rbx)
add    $0x2c,%al
movzbl %al,%eax
not    %eax
mov    %eax,0xc(%rsp)
mov    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
call   1090 <memcpy@plt>
mov    (%r14),%al
mov    %al,0xa(%rbx)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1040 <ByteToHexStr@plt>
lea    0xd8e(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
call   10d0 <UART_Send@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    12f0 <main+0x130>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12f9 <main+0x139>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
call   1080 <fprintf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%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 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"Sending:\0A %s \0A\00"
@stdin = global i32 0
@.str.3 = [38 x i8] c"Error:inputID cannot large than 253.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [50 x i8]
%9 = alloca i8*
store i32 0, i32* %1
%10 = call i32 (...) @InitSerial()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %91
16: ; preds = %0
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 253
br i1 %19, label %20, label %83
20: ; preds = %16
%21 = load i32, i32* %3
%22 = and i32 %21, 255
store i32 %22, i32* %3
%23 = bitcast i32* %3 to i8*
store i8* %23, i8** %4
%24 = call i64 @malloc(i32 11)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %5
%26 = load i8*, i8** %5
store i8 -1, i8* %26
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 -1, i8* %28
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 2
store i8 %30, i8* %32
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8 7, i8* %34
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8 3, i8* %36
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 5
store i8 30, i8* %38
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 6
store i8 0, i8* %40
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 7
store i8 2, i8* %42
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 8
store i8 0, i8* %44
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 9
store i8 2, i8* %46
%47 = load i8*, i8** %4
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 7
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 33
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 4
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = and i32 %56, 255
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = xor i32 %58, -1
store i32 %59, i32* %6
%60 = call i64 @malloc(i32 1)
%61 = inttoptr i64 %60 to i8*
store i8* %61, i8** %7
%62 = load i8*, i8** %7
%63 = call i32 @memcpy(i8* %62, i32* %6, i32 1)
%64 = load i8*, i8** %7
%65 = load i8, i8* %64
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i64 10
store i8 %65, i8* %67
%68 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
store i8* %68, i8** %9
%69 = load i8*, i8** %9
%70 = call i32 @memset(i8* %69, i32 0, i32 50)
%71 = load i8*, i8** %5
%72 = load i8*, i8** %9
%73 = call i32 @ByteToHexStr(i8* %71, i8* %72, i32 11)
%74 = load i8*, i8** %9
%75 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %74)
%76 = load i32, i32* %2
%77 = load i8*, i8** %5
%78 = call i32 @UART_Send(i32 %76, i8* %77, i32 11)
%79 = load i8*, i8** %5
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %7
%82 = call i32 @free(i8* %81)
br label %88
83: ; preds = %16
%84 = load i32, i32* @stdin
%85 = call i32 @fflush(i32 %84)
%86 = load i32, i32* @stderr
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %88
88: ; preds = %83, %20
%89 = load i32, i32* %2
%90 = call i32 @close(i32 %89)
br label %91
91: ; preds = %88, %13
%92 = load i32, i32* %1
ret i32 %92
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"InitSerial Error!\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"Sending:\0A %s \0A\00"
@stdin = global i32 0
@.str.3 = [38 x i8] c"Error:inputID cannot large than 253.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = tail call i32 (...) @InitSerial()
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %51
9: ; preds = %0
%10 = bitcast i32* %1 to i8*
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 253
br i1 %13, label %14, label %44
14: ; preds = %9
%15 = and i32 %12, 255
store i32 %15, i32* %1
%16 = call i64 @malloc(i32 11)
%17 = inttoptr i64 %16 to i8*
store i8 -1, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 -1, i8* %18
%19 = load i8, i8* %10
%20 = getelementptr inbounds i8, i8* %17, i64 2
store i8 %19, i8* %20
%21 = getelementptr inbounds i8, i8* %17, i64 3
store i8 7, i8* %21
%22 = getelementptr inbounds i8, i8* %17, i64 4
store i8 3, i8* %22
%23 = getelementptr inbounds i8, i8* %17, i64 5
store i8 30, i8* %23
%24 = getelementptr inbounds i8, i8* %17, i64 6
store i8 0, i8* %24
%25 = getelementptr inbounds i8, i8* %17, i64 7
store i8 2, i8* %25
%26 = getelementptr inbounds i8, i8* %17, i64 8
store i8 0, i8* %26
%27 = getelementptr inbounds i8, i8* %17, i64 9
store i8 2, i8* %27
%28 = bitcast i32* %2 to i8*
%29 = add i8 %19, 44
%30 = zext i8 %29 to i32
%31 = xor i32 %30, -1
store i32 %31, i32* %2
%32 = call i64 @malloc(i32 1)
%33 = inttoptr i64 %32 to i8*
%34 = call i32 @memcpy(i8* %33, i32* %2, i32 1)
%35 = load i8, i8* %33
%36 = getelementptr inbounds i8, i8* %17, i64 10
store i8 %35, i8* %36
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 50)
%39 = call i32 @ByteToHexStr(i8* %17, i8* %37, i32 11)
%40 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%41 = call i32 @UART_Send(i32 %4, i8* %17, i32 11)
%42 = call i32 @free(i8* %17)
%43 = call i32 @free(i8* %33)
br label %49
44: ; preds = %9
%45 = load i32, i32* @stdin
%46 = call i32 @fflush(i32 %45)
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %44, %14
%50 = call i32 @close(i32 %4)
br label %51
51: ; preds = %49, %6
%52 = phi i32 [ -1, %6 ], [ 0, %49 ]
ret i32 %52
}