#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*/ assert(int);
scalar_t__ luart_chkrxc_(unsigned int);
int luart_chkrxi_(unsigned int);
int luart_getrxd_(unsigned int);
int /*<<< orphan*/ luart_setrxi_(unsigned int, int);
int luart_getc(unsigned num) {
  assert(num < 2);
  int s = luart_chkrxi_(num);
  luart_setrxi_(num, 0);
  while (luart_chkrxc_(num) == 0)
    ;
  int c = luart_getrxd_(num);
  luart_setrxi_(num, s);
  return c;
}


x86 assembly (clang, -O0):
<luart_getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
call   1050 <luart_chkrxi_@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1070 <luart_setrxi_@plt>
mov    -0x4(%rbp),%edi
call   1060 <luart_chkrxc_@plt>
cmp    $0x0,%rax
jne    1198 <luart_getc+0x48>
jmp    1181 <luart_getc+0x31>
mov    -0x4(%rbp),%edi
call   1030 <luart_getrxd_@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <luart_setrxi_@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luart_getc>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0x2,%ebx
setb   %dil
call   1040 <assert@plt>
mov    %ebx,%edi
call   1050 <luart_chkrxi_@plt>
mov    %eax,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <luart_setrxi_@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1060 <luart_chkrxc_@plt>
test   %rax,%rax
je     1180 <luart_getc+0x30>
mov    %ebx,%edi
call   1030 <luart_getrxd_@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14d,%esi
call   1070 <luart_setrxi_@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @luart_getc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ult i32 %5, 2
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %2
%10 = call i32 @luart_chkrxi_(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = call i32 @luart_setrxi_(i32 %11, i32 0)
br label %13
13: ; preds = %17, %1
%14 = load i32, i32* %2
%15 = call i64 @luart_chkrxc_(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i32 @luart_getrxd_(i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @luart_setrxi_(i32 %21, i32 %22)
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @luart_getc(i32 %0) {
%2 = icmp ult i32 %0, 2
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @luart_chkrxi_(i32 %0)
%6 = tail call i32 @luart_setrxi_(i32 %0, i32 0)
br label %7
7: ; preds = %7, %1
%8 = tail call i64 @luart_chkrxc_(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %7, label %10
10: ; preds = %7
%11 = tail call i32 @luart_getrxd_(i32 %0)
%12 = tail call i32 @luart_setrxi_(i32 %0, i32 %5)
ret i32 %11
}