#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 OpenDev(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sent_cmd(int, char *, unsigned char *, char *);
scalar_t__ set_Parity(int, int, int, char);
int /*<<< orphan*/ set_speed(int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ string_2_hex(char *, char *);
int main(int argc, char **argv) {
  int fd;
  int nread;
  int i;
  char *cmd = "010300000002C40B##";
  unsigned char data[8];
  char *dev = "/dev/ttyS0";
  fd = OpenDev(dev);
  if (fd > 0)
    set_speed(fd, 9600);
  else {
    printf("Can't Open Serial Port!\n");
    exit(0);
  }
  if (set_Parity(fd, 8, 1, 'N') == 0) {
    printf("Set Parity Error\n");
    exit(1);
  }
  unsigned char buff[1024];
  char buff2[64] = {'\0'};
  string_2_hex(cmd, buff2);
  while (1) {
    memset(buff, 0, 10);
    sent_cmd(fd, buff2, buff, "temp");
    for (i = 0; i < 10; ++i)
      printf("%02x  ", buff[i]);
    printf("\n");
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe58(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <OpenDev@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e7 <main+0x57>
mov    -0x14(%rbp),%edi
mov    $0x2580,%esi
call   1070 <set_speed@plt>
jmp    11fc <main+0x6c>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1060 <set_Parity@plt>
cmp    $0x0,%rax
jne    1235 <main+0xa5>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x480(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    -0x480(%rbp),%rsi
call   1050 <string_2_hex@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x480(%rbp),%rsi
lea    -0x440(%rbp),%rdx
lea    0xdc6(%rip),%rcx
call   10a0 <sent_cmd@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    12c1 <main+0x131>
movslq -0x1c(%rbp),%rax
movzbl -0x440(%rbp,%rax,1),%esi
ff
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    128f <main+0xff>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    1258 <main+0xc8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x440,%rsp
lea    0xe4d(%rip),%rdi
call   10a0 <OpenDev@plt>
test   %eax,%eax
jle    130f <main+0x15f>
mov    %eax,%r12d
mov    %eax,%edi
mov    $0x2580,%esi
call   1090 <set_speed@plt>
mov    %r12d,%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1080 <set_Parity@plt>
test   %rax,%rax
je     1322 <main+0x172>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xde1(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1070 <string_2_hex@plt>
lea    0x40(%rsp),%rbx
lea    0xde8(%rip),%r15
lea    0xde6(%rip),%rbp
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   10c0 <sent_cmd@plt>
movzbl 0x40(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x41(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x42(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x43(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x44(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x45(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x46(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x47(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x48(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x49(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
jmp    1240 <main+0x90>
lea    0xd14(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd19(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"010300000002C40B##\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.2 = [25 x i8] c"Can't Open Serial Port!\0A\00"
@.str.3 = [18 x i8] c"Set Parity Error\0A\00"
@.str.4 = [5 x i8] c"temp\00"
@.str.5 = [7 x i8] c"%02x \00"
@.str.6 = [2 x i8] c"\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 i8*
%10 = alloca [8 x i8]
%11 = alloca i8*
%12 = alloca [1024 x i8]
%13 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %11
%14 = load i8*, i8** %11
%15 = call i32 @OpenDev(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i32 @set_speed(i32 %19, i32 9600)
br label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %18
%25 = load i32, i32* %6
%26 = call i64 @set_Parity(i32 %25, i32 8, i32 1, i8 signext 78)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = bitcast [64 x i8]* %13 to i8*
%33 = load i8*, i8** %9
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%35 = call i32 @string_2_hex(i8* %33, i8* %34)
br label %36
36: ; preds = %31, %56
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 10)
%39 = load i32, i32* %6
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%42 = call i32 @sent_cmd(i32 %39, i8* %40, i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %43
43: ; preds = %53, %36
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %56
46: ; preds = %43
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %46
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %43
56: ; preds = %43
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%58 = call i32 @sleep(i32 1)
br label %36
}

LLVM IR (-O2):
@.str = [19 x i8] c"010300000002C40B##\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.4 = [5 x i8] c"temp\00"
@.str.5 = [7 x i8] c"%02x \00"
@str = [24 x i8] c"Can't Open Serial Port!\00"
@str.7 = [17 x i8] c"Set Parity Error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [64 x i8]
%5 = tail call i32 @OpenDev(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @set_speed(i32 %5, i32 9600)
%9 = tail call i64 @set_Parity(i32 %5, i32 8, i32 1, i8 signext 78)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %17
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %7
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%20 = call i32 @string_2_hex(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 6
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 7
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 9
br label %30
30: ; preds = %30, %17
%31 = call i32 @memset(i8* %18, i32 0, i32 10)
%32 = call i32 @sent_cmd(i32 %5, i8* %19, i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%33 = load i8, i8* %18
%34 = zext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load i8, i8* %21
%37 = zext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i8, i8* %22
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load i8, i8* %23
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%45 = load i8, i8* %24
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = load i8, i8* %25
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i8, i8* %26
%52 = zext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i8, i8* %27
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%57 = load i8, i8* %28
%58 = zext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = load i8, i8* %29
%61 = zext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %61)
%63 = call i32 @putchar(i32 10)
%64 = call i32 @sleep(i32 1)
br label %30
}