#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 */
scalar_t__ RS232_OpenComport(int, int, char *);
int /*<<< orphan*/ RS232_cputs(int, char *);
int /*<<< orphan*/ api_uart_read(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usleep(int);
int main() {
  int cport_nr = 24;
  int bdrate = 115200;
  int n = 0;
  char mode[] = {'8', 'N', '1', 0};
  char buf_send[20];
  char buf_recv[20];
  strcpy(buf_send, "ssss");
  if (RS232_OpenComport(cport_nr, bdrate, mode)) {
    printf("Can not open comport\n");
    return (0);
  }
  while (1) {
    RS232_cputs(cport_nr, buf_send);
    printf("sent: %s\n", buf_send);
    usleep(1000000);
    api_uart_read(cport_nr, buf_recv);
    printf("nhan: %s", buf_recv);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x18,-0x8(%rbp)
movl   $0x1c200,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0xe76(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x14(%rbp),%rdx
call   1070 <RS232_OpenComport@plt>
cmp    $0x0,%rax
je     11cc <main+0x6c>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret
jmp    11d1 <main+0x71>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <RS232_cputs@plt>
lea    -0x30(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <api_uart_read@plt>
lea    -0x50(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d1 <main+0x71>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x314e38,0xc(%rsp)
lea    0xe76(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xc(%rsp),%rdx
mov    $0x18,%edi
mov    $0x1c200,%esi
call   1080 <RS232_OpenComport@plt>
test   %rax,%rax
je     11c7 <main+0x57>
lea    0xe64(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x10(%rsp),%r15
lea    0xe32(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0xe30(%rip),%r12
nop
mov    $0x18,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x18,%edi
mov    %rbx,%rsi
call   1050 <api_uart_read@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@__const.main.mode = [4 x i8] c"8N1\00"
@.str = [5 x i8] c"ssss\00"
@.str.1 = [22 x i8] c"Can not open comport\0A\00"
@.str.2 = [10 x i8] c"sent: %s\0A\00"
@.str.3 = [9 x i8] c"nhan: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
store i32 0, i32* %1
store i32 24, i32* %2
store i32 115200, i32* %3
store i32 0, i32* %4
%8 = bitcast [4 x i8]* %5 to i8*
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%14 = call i64 @RS232_OpenComport(i32 %11, i32 %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
18: ; preds = %0
br label %19
19: ; preds = %18, %19
%20 = load i32, i32* %2
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%22 = call i32 @RS232_cputs(i32 %20, i8* %21)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @usleep(i32 1000000)
%26 = load i32, i32* %2
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%28 = call i32 @api_uart_read(i32 %26, i8* %27)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %29)
br label %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"ssss\00"
@.str.2 = [10 x i8] c"sent: %s\0A\00"
@.str.3 = [9 x i8] c"nhan: %s\00"
@str = [21 x i8] c"Can not open comport\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = bitcast i32* %1 to i8*
store i32 3231288, i32* %1
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @RS232_OpenComport(i32 24, i32 115200, i8* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
ret i32 0
12: ; preds = %0, %12
%13 = call i32 @RS232_cputs(i32 24, i8* %5)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%15 = call i32 @usleep(i32 1000000)
%16 = call i32 @api_uart_read(i32 24, i8* %6)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %12
}