#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*/ RS232_CloseComport(int);
scalar_t__ RS232_OpenComport(int, int, char *);
int /*<<< orphan*/ RS232_cputs(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usleep(int);
int main() {
  int i = 0, cport_nr = 16, bdrate = 115200, j = 0;
  char mode[] = {'8', 'N', '1', 0}, str[2][512];
  strcpy(str[0], "The quick brown fox jumped over the lazy grey dog.\n");
  strcpy(str[1], "Happy serial programming!\n");
  if (RS232_OpenComport(cport_nr, bdrate, mode)) {
    printf("Can not open comport\n");
    return (0);
  }
  while (j < 10) {
    RS232_cputs(cport_nr, str[i]);
    printf("sent: %s\n", str[i]);
    usleep(1000000);
    i++;
    j++;
    i %= 2;
  }
  RS232_CloseComport(cport_nr);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x10,-0xc(%rbp)
movl   $0x1c200,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe6c(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
add    $0x200,%rdi
lea    0xe79(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1070 <RS232_OpenComport@plt>
cmp    $0x0,%rax
je     11f7 <main+0x97>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127e <main+0x11e>
jmp    11fc <main+0x9c>
cmpl   $0xa,-0x14(%rbp)
jge    126f <main+0x10f>
mov    -0xc(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x420(%rbp),%rsi
shl    $0x9,%rax
add    %rax,%rsi
call   1060 <RS232_cputs@plt>
movslq -0x8(%rbp),%rax
lea    -0x420(%rbp),%rsi
shl    $0x9,%rax
add    %rax,%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xf4240,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
jmp    11fc <main+0x9c>
mov    -0xc(%rbp),%edi
call   1050 <RS232_CloseComport@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
movl   $0x314e38,0xc(%rsp)
lea    0xe75(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x210(%rsp),%rbx
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xc(%rsp),%rdx
mov    $0x10,%edi
mov    $0x1c200,%esi
call   1080 <RS232_OpenComport@plt>
test   %rax,%rax
je     11d6 <main+0x66>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
jmp    1354 <main+0x1e4>
lea    0x10(%rsp),%r15
mov    $0x10,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
lea    0xe60(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %r15,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
call   1060 <RS232_CloseComport@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.mode = [4 x i8] c"8N1\00"
@.str = [52 x i8] c"The quick brown fox jumped over the lazy grey dog.\0A\00"
@.str.1 = [27 x i8] c"Happy serial programming!\0A\00"
@.str.2 = [22 x i8] c"Can not open comport\0A\00"
@.str.3 = [10 x i8] c"sent: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = alloca [2 x [512 x i8]]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 16, i32* %3
store i32 115200, i32* %4
store i32 0, i32* %5
%8 = bitcast [4 x i8]* %6 to i8*
%9 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %7, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %7, i64 0, i64 1
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%18 = call i64 @RS232_OpenComport(i32 %15, i32 %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %48
22: ; preds = %0
br label %23
23: ; preds = %26, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %7, i64 0, i64 %29
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %30, i64 0, i64 0
%32 = call i32 @RS232_cputs(i32 %27, i8* %31)
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %7, i64 0, i64 %34
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %35, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 @usleep(i32 1000000)
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
%43 = load i32, i32* %2
%44 = srem i32 %43, 2
store i32 %44, i32* %2
br label %23
45: ; preds = %23
%46 = load i32, i32* %3
%47 = call i32 @RS232_CloseComport(i32 %46)
store i32 0, i32* %1
br label %48
48: ; preds = %45, %20
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [52 x i8] c"The quick brown fox jumped over the lazy grey dog.\0A\00"
@.str.1 = [27 x i8] c"Happy serial programming!\0A\00"
@.str.3 = [10 x i8] c"sent: %s\0A\00"
@str = [21 x i8] c"Can not open comport\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x [512 x i8]]
%3 = bitcast i32* %1 to i8*
store i32 3231288, i32* %1
%4 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %2, i64 0, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %2, i64 0, i64 1, i64 0
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%8 = call i64 @RS232_OpenComport(i32 16, i32 115200, i8* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %0
%11 = call i32 @RS232_cputs(i32 16, i8* %4)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%13 = call i32 @usleep(i32 1000000)
%14 = call i32 @RS232_cputs(i32 16, i8* %6)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%16 = call i32 @usleep(i32 1000000)
%17 = call i32 @RS232_cputs(i32 16, i8* %4)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%19 = call i32 @usleep(i32 1000000)
%20 = call i32 @RS232_cputs(i32 16, i8* %6)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%22 = call i32 @usleep(i32 1000000)
%23 = call i32 @RS232_cputs(i32 16, i8* %4)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%25 = call i32 @usleep(i32 1000000)
%26 = call i32 @RS232_cputs(i32 16, i8* %6)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%28 = call i32 @usleep(i32 1000000)
%29 = call i32 @RS232_cputs(i32 16, i8* %4)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%31 = call i32 @usleep(i32 1000000)
%32 = call i32 @RS232_cputs(i32 16, i8* %6)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%34 = call i32 @usleep(i32 1000000)
%35 = call i32 @RS232_cputs(i32 16, i8* %4)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%37 = call i32 @usleep(i32 1000000)
%38 = call i32 @RS232_cputs(i32 16, i8* %6)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%40 = call i32 @usleep(i32 1000000)
%41 = call i32 @RS232_CloseComport(i32 16)
br label %44
42: ; preds = %0
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %10, %42
ret i32 0
}