#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*/ CloseGPin(int);
int /*<<< orphan*/ GetPinValue(int);
int /*<<< orphan*/ InitPin(int);
int /*<<< orphan*/ LEDOff(int);
int /*<<< orphan*/ LEDOn(int);
int /*<<< orphan*/ Nullize(char *, int);
int /*<<< orphan*/ SetPinDirt(int, char *);
int /*<<< orphan*/ UART_Baudrate_NonC(int, int, int /*<<< orphan*/, int);
int UART_init(int, char);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i;
  int cnt;
  int UART1_News = 1;
  int UART2_News = 1;
  int readfromUART1 = 0;
  int readfromUART2 = 0;
  int UART1T = 0;
  int UART1R = 0;
  int UART2T = 0;
  int UART2R = 0;
  char buf[100] = {
      '\0',
  };
  char buf1[100] = {
      '\0',
  };
  char UART1_data[300];
  char UART2_data[300];
  LEDOn(23);
  LEDOn(47);
  InitPin(27);
  SetPinDirt(27, "in");
  printf("Start\n");
  UART1T = UART_init(1, 'T');
  printf("UART1T : %d\n", UART1T);
  UART1R = UART_init(1, 'R');
  printf("UART1R : %d\n", UART1R);
  UART_Baudrate_NonC(UART1T, 9600, 0, 1);
  printf("START!\n");
  write(UART1T, "START!\n", 8);
  while (!GetPinValue(27)) {
    readfromUART1 = read(UART1R, buf, 100);
    if (readfromUART1 != -1) {
      printf("|%s|%i|\n", buf, readfromUART1);
      Nullize(buf, readfromUART1);
    } else {
      usleep(200000);
      write(UART1T, "z", 2);
    }
  }
  write(UART1T, "End\n", 5);
  printf("End\n");
  CloseGPin(27);
  LEDOff(23);
  LEDOff(47);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   10a0 <memset@plt>
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   10a0 <memset@plt>
mov    $0x17,%edi
call   10f0 <LEDOn@plt>
mov    $0x2f,%edi
call   10f0 <LEDOn@plt>
mov    $0x1b,%edi
call   1030 <InitPin@plt>
mov    $0x1b,%edi
lea    0xd86(%rip),%rsi
call   10d0 <SetPinDirt@plt>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
mov    $0x54,%esi
call   1080 <UART_init@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
mov    $0x52,%esi
call   1080 <UART_init@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x20(%rbp),%edi
mov    $0x2580,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1050 <UART_Baudrate_NonC@plt>
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x20(%rbp),%edi
lea    0xd25(%rip),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    $0x1b,%edi
call   10c0 <GetPinValue@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1328 <main+0x148>
jmp    1398 <main+0x1b8>
mov    -0x24(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   10b0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1375 <main+0x195>
lea    -0x90(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <Nullize@plt>
jmp    1393 <main+0x1b3>
mov    $0x30d40,%edi
call   1100 <usleep@plt>
mov    -0x20(%rbp),%edi
lea    0xcac(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
jmp    1309 <main+0x129>
mov    -0x20(%rbp),%edi
lea    0xc95(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1b,%edi
call   10e0 <CloseGPin@plt>
mov    $0x17,%edi
call   1070 <LEDOff@plt>
mov    $0x2f,%edi
call   1070 <LEDOff@plt>
xor    %eax,%eax
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    $0x17,%edi
call   10f0 <LEDOn@plt>
mov    $0x2f,%edi
call   10f0 <LEDOn@plt>
mov    $0x1b,%edi
call   1030 <InitPin@plt>
lea    0xdc5(%rip),%rsi
mov    $0x1b,%edi
call   10d0 <SetPinDirt@plt>
lea    0xde9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
mov    $0x54,%esi
call   1090 <UART_init@plt>
mov    %eax,%r14d
lea    0xd99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x1,%edi
mov    $0x52,%esi
call   1090 <UART_init@plt>
mov    %eax,%r13d
lea    0xd84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
mov    $0x2580,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <UART_Baudrate_NonC@plt>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xd61(%rip),%rsi
mov    %r14d,%edi
mov    $0x8,%edx
call   1050 <write@plt>
mov    $0x1b,%edi
call   10c0 <GetPinValue@plt>
test   %eax,%eax
je     1326 <main+0x146>
lea    0xd52(%rip),%rsi
mov    %r14d,%edi
mov    $0x5,%edx
call   1050 <write@plt>
lea    0xd50(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1b,%edi
call   10e0 <CloseGPin@plt>
mov    $0x17,%edi
call   1080 <LEDOff@plt>
mov    $0x2f,%edi
call   1080 <LEDOff@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xcfe(%rip),%r15
lea    0xcee(%rip),%r12
jmp    136c <main+0x18c>
nopl   0x0(%rax)
mov    $0x30d40,%edi
call   1100 <usleep@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    $0x1b,%edi
call   10c0 <GetPinValue@plt>
test   %eax,%eax
jne    12d7 <main+0xf7>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   10b0 <read@plt>
cmp    $0xffffffff,%eax
je     1340 <main+0x160>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <Nullize@plt>
jmp    135a <main+0x17a>

LLVM IR (-O0):
@.str = [3 x i8] c"in\00"
@.str.1 = [7 x i8] c"Start\0A\00"
@.str.2 = [13 x i8] c"UART1T : %d\0A\00"
@.str.3 = [13 x i8] c"UART1R : %d\0A\00"
@.str.4 = [8 x i8] c"START!\0A\00"
@.str.5 = [9 x i8] c"|%s|%i|\0A\00"
@.str.6 = [2 x i8] c"z\00"
@.str.7 = [5 x i8] c"End\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100 x i8]
%13 = alloca [100 x i8]
%14 = alloca [300 x i8]
%15 = alloca [300 x i8]
store i32 0, i32* %1
store i32 1, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%16 = bitcast [100 x i8]* %12 to i8*
%17 = bitcast [100 x i8]* %13 to i8*
%18 = call i32 @LEDOn(i32 23)
%19 = call i32 @LEDOn(i32 47)
%20 = call i32 @InitPin(i32 27)
%21 = call i32 @SetPinDirt(i32 27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @UART_init(i32 1, i8 signext 84)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = call i32 @UART_init(i32 1, i8 signext 82)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %8
%30 = call i32 @UART_Baudrate_NonC(i32 %29, i32 9600, i32 0, i32 1)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %8
%33 = call i32 @write(i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %34
34: ; preds = %55, %0
%35 = call i32 @GetPinValue(i32 27)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %56
38: ; preds = %34
%39 = load i32, i32* %9
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 100)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %51
44: ; preds = %38
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %45, i32 %46)
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%49 = load i32, i32* %6
%50 = call i32 @Nullize(i8* %48, i32 %49)
br label %55
51: ; preds = %38
%52 = call i32 @usleep(i32 200000)
%53 = load i32, i32* %8
%54 = call i32 @write(i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 2)
br label %55
55: ; preds = %51, %44
br label %34
56: ; preds = %34
%57 = load i32, i32* %8
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 5)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%60 = call i32 @CloseGPin(i32 27)
%61 = call i32 @LEDOff(i32 23)
%62 = call i32 @LEDOff(i32 47)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"in\00"
@.str.2 = [13 x i8] c"UART1T : %d\0A\00"
@.str.3 = [13 x i8] c"UART1R : %d\0A\00"
@.str.4 = [8 x i8] c"START!\0A\00"
@.str.5 = [9 x i8] c"|%s|%i|\0A\00"
@.str.6 = [2 x i8] c"z\00"
@.str.7 = [5 x i8] c"End\0A\00"
@str = [6 x i8] c"Start\00"
@str.8 = [7 x i8] c"START!\00"
@str.9 = [4 x i8] c"End\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @LEDOn(i32 23)
%4 = tail call i32 @LEDOn(i32 47)
%5 = tail call i32 @InitPin(i32 27)
%6 = tail call i32 @SetPinDirt(i32 27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @UART_init(i32 1, i8 signext 84)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32 @UART_init(i32 1, i8 signext 82)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = tail call i32 @UART_Baudrate_NonC(i32 %8, i32 9600, i32 0, i32 1)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
%14 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 8)
%15 = call i32 @GetPinValue(i32 27)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %0, %26
%18 = call i32 @read(i32 %10, i8* %2, i32 100)
%19 = icmp eq i32 %18, -1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 %18)
%22 = call i32 @Nullize(i8* %2, i32 %18)
br label %26
23: ; preds = %17
%24 = call i32 @usleep(i32 200000)
%25 = call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 2)
br label %26
26: ; preds = %23, %20
%27 = call i32 @GetPinValue(i32 27)
%28 = icmp eq i32 %27, 0
br i1 %28, label %17, label %29
29: ; preds = %26, %0
%30 = call i32 @write(i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 5)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0))
%32 = call i32 @CloseGPin(i32 27)
%33 = call i32 @LEDOff(i32 23)
%34 = call i32 @LEDOff(i32 47)
ret i32 0
}