#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
int OpenDev(char *);
int ascii_to_integer(char *);
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int set_Parity(int, int, int, char);
int /*<<< orphan*/ set_speed(int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int fd;
  int nread;
  int speedcom;
  char buff[512];
  time_t nowtime;
  time(&nowtime);
  printf("%s", asctime(gmtime(&nowtime)));
  char *command = argv[3];
  fd = OpenDev(argv[2]);
  printf("fd: %u\n", fd);
  printf("open tty: %s\n", argv[2]);
  if (fd > 0) {
    speedcom = ascii_to_integer(argv[1]);
    printf("speedcom: %d\n", speedcom);
    set_speed(fd, speedcom);
    printf("open fd: %u\n", fd);
  } else {
    printf("Can't Open Serial Port!\n");
    exit(0);
  }
  if (set_Parity(fd, 8, 1, 'N') == -1) {
    printf("Set Parity Error\n");
    exit(1);
  }
  while (1) {
    while (nread = read(fd, buff, 512)) {
      buff[nread + 1] = '\0';
    }
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x224(%rbp),%rdi
call   1080 <time@plt>
lea    -0x224(%rbp),%rdi
call   10a0 <gmtime@plt>
mov    %eax,%edi
call   1030 <asctime@plt>
mov    %rax,%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x230(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <OpenDev@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    127b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <ascii_to_integer@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1090 <set_speed@plt>
mov    -0x14(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1290 <main+0xf0>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1070 <set_Parity@plt>
cmp    $0xffffffff,%eax
jne    12c8 <main+0x128>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12cd <main+0x12d>
jmp    12d2 <main+0x132>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1307 <main+0x167>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x220(%rbp,%rax,1)
jmp    12d2 <main+0x132>
jmp    12cd <main+0x12d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rsi,%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <time@plt>
mov    %rbx,%rdi
call   10b0 <gmtime@plt>
mov    %eax,%edi
call   1040 <asctime@plt>
lea    0xe1f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rdi
call   10c0 <OpenDev@plt>
mov    %eax,%ebp
lea    0xe27(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    12bc <main+0x10c>
mov    0x8(%r14),%rdi
call   1070 <ascii_to_integer@plt>
mov    %eax,%ebx
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   10a0 <set_speed@plt>
lea    0xdd4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x4e,%ecx
call   1080 <set_Parity@plt>
cmp    $0xffffffff,%eax
je     12cf <main+0x11f>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1280 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cltq
movb   $0x0,0x1(%rax,%rbx,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    12a0 <main+0xf0>
jmp    1280 <main+0xd0>
lea    0xd69(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"fd: %u\0A\00"
@.str.2 = [14 x i8] c"open tty: %s\0A\00"
@.str.3 = [14 x i8] c"speedcom: %d\0A\00"
@.str.4 = [13 x i8] c"open fd: %u\0A\00"
@.str.5 = [25 x i8] c"Can't Open Serial Port!\0A\00"
@.str.6 = [18 x i8] c"Set Parity Error\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 [512 x i8]
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @time(i32* %10)
%13 = call i32 @gmtime(i32* %10)
%14 = call i8* @asctime(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 3
%18 = load i8*, i8** %17
store i8* %18, i8** %11
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @OpenDev(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @ascii_to_integer(i8* %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %8
%40 = call i32 @set_speed(i32 %38, i32 %39)
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %46
43: ; preds = %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %31
%47 = load i32, i32* %6
%48 = call i32 @set_Parity(i32 %47, i32 8, i32 1, i8 signext 78)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
br label %54
54: ; preds = %53, %65
br label %55
55: ; preds = %60, %54
%56 = load i32, i32* %6
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%58 = call i32 @read(i32 %56, i8* %57, i32 512)
store i32 %58, i32* %7
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %63
store i8 0, i8* %64
br label %55
65: ; preds = %55
br label %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"fd: %u\0A\00"
@.str.2 = [14 x i8] c"open tty: %s\0A\00"
@.str.3 = [14 x i8] c"speedcom: %d\0A\00"
@.str.4 = [13 x i8] c"open fd: %u\0A\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 %1) {
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i32 @time(i32* %4)
%8 = call i32 @gmtime(i32* %4)
%9 = call i8* @asctime(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = call i32 @OpenDev(i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %11
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = icmp sgt i32 %13, 0
br i1 %17, label %18, label %27
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @ascii_to_integer(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 @set_speed(i32 %13, i32 %21)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%25 = call i32 @set_Parity(i32 %13, i32 8, i32 1, i8 signext 78)
%26 = icmp eq i32 %25, -1
br i1 %26, label %30, label %33
27: ; preds = %2
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %18
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18, %36
%34 = call i32 @read(i32 %13, i8* %5, i32 512)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %37, %33
br label %33
37: ; preds = %33, %37
%38 = phi i32 [ %42, %37 ], [ %34, %33 ]
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @read(i32 %13, i8* %5, i32 512)
%43 = icmp eq i32 %42, 0
br i1 %43, label %36, label %37
}