#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*/ useconds_t;

/* Variables and functions */
int RS232_PollComport(int, unsigned char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ usleep(int /*<<< orphan*/);
int ReadComport(int cport_nr, unsigned char *buf, int size, useconds_t count) {
  int n;
  n = 0;
  usleep(count);
  while (1) {
    n = RS232_PollComport(cport_nr, buf, size);
    if (n > 0) {
      buf[n] = 0;
      printf("%s\n", (char *)buf);
      break;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<ReadComport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <RS232_PollComport@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1191 <ReadComport+0x61>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
jmp    1196 <ReadComport+0x66>
jmp    1154 <ReadComport+0x24>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadComport>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%ebx
mov    %ecx,%edi
call   1050 <usleep@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <RS232_PollComport@plt>
test   %eax,%eax
jle    1150 <ReadComport+0x20>
mov    %eax,%ebp
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
lea    0xe8f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @ReadComport(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %8
%11 = call i32 @usleep(i32 %10)
br label %12
12: ; preds = %4, %26
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @RS232_PollComport(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %6
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %27
26: ; preds = %12
br label %12
27: ; preds = %19
%28 = load i32, i32* %9
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @ReadComport(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @usleep(i32 %3)
br label %6
6: ; preds = %6, %4
%7 = tail call i32 @RS232_PollComport(i32 %0, i8* %1, i32 %2)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %6
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
ret i32 %7
}