#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*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usleep(int);
int main() {
  int i = 0, cport_nr = 0, bdrate = 9600;
  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 (1) {
    RS232_cputs(cport_nr, str[i]);
    printf("sent: %s\n", str[i]);
    usleep(1000000);
    i++;
    i %= 2;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2580,-0x10(%rbp)
mov    0xe83(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
add    $0x200,%rdi
lea    0xe90(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x14(%rbp),%rdx
call   1060 <RS232_OpenComport@plt>
cmp    $0x0,%rax
je     11df <main+0x8f>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret
jmp    11e4 <main+0x94>
mov    -0xc(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    -0x420(%rbp),%rsi
shl    $0x9,%rax
mov    %rax,-0x448(%rbp)
add    %rax,%rsi
mov    %rsi,-0x440(%rbp)
call   1050 <RS232_cputs@plt>
movslq -0x8(%rbp),%rax
lea    -0x420(%rbp),%rsi
shl    $0x9,%rax
mov    %rax,-0x438(%rbp)
add    %rax,%rsi
mov    %rsi,-0x430(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xf4240,%edi
call   1070 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
jmp    11e4 <main+0x94>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
movl   $0x314e38,0xc(%rsp)
lea    0xe85(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x210(%rsp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xc(%rsp),%rdx
xor    %edi,%edi
mov    $0x2580,%esi
call   1070 <RS232_OpenComport@plt>
test   %rax,%rax
je     11ca <main+0x6a>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe7e(%rip),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%eax
shl    $0x9,%rax
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <RS232_cputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   1080 <usleep@plt>
mov    %r15d,%eax
add    $0x1,%eax
shr    $0x1f,%eax
add    %r15d,%eax
add    $0x1,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %eax,%r15d
add    $0x1,%r15d
jmp    11e0 <main+0x80>

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 [4 x i8]
%6 = alloca [2 x [512 x i8]]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 9600, i32* %4
%7 = bitcast [4 x i8]* %5 to i8*
%8 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %6, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %6, i64 0, i64 1
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%17 = call i64 @RS232_OpenComport(i32 %14, i32 %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
21: ; preds = %0
br label %22
22: ; preds = %21, %22
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %6, i64 0, i64 %25
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %26, i64 0, i64 0
%28 = call i32 @RS232_cputs(i32 %23, i8* %27)
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %6, i64 0, i64 %30
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %31, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 @usleep(i32 1000000)
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = srem i32 %37, 2
store i32 %38, i32* %2
br label %22
}

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 0, i32 9600, i8* %3)
%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 = phi i32 [ %20, %12 ], [ 0, %0 ]
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %2, i64 0, i64 %14, i64 0
%16 = call i32 @RS232_cputs(i32 0, i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%18 = call i32 @usleep(i32 1000000)
%19 = add nsw i32 %13, 1
%20 = srem i32 %19, 2
br label %12
}