#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_chktxc_(unsigned int);
int luart_chktxi_(unsigned int);
int luart_puttxd_(unsigned int, int);
int /*<<< orphan*/ luart_settxi_(unsigned int, int);
int luart_putc(unsigned num, int c) {
  assert(num < 2);
  int s = luart_chktxi_(num);
  luart_settxi_(num, 0);
  while (luart_chktxc_(num) == 0)
    ;
  c = luart_puttxd_(num, c);
  luart_settxi_(num, s);
  return c;
}


x86 assembly (clang, -O0):
<luart_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x2,-0x4(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%edi
call   1040 <luart_chktxi_@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1070 <luart_settxi_@plt>
mov    -0x4(%rbp),%edi
call   1060 <luart_chktxc_@plt>
cmp    $0x0,%rax
jne    119b <luart_putc+0x4b>
jmp    1184 <luart_putc+0x34>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <luart_puttxd_@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <luart_settxi_@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luart_putc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0x2,%ebx
setb   %dil
call   1050 <assert@plt>
mov    %ebx,%edi
call   1040 <luart_chktxi_@plt>
mov    %eax,%r15d
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <luart_settxi_@plt>
nopl   (%rax)
mov    %ebx,%edi
call   1060 <luart_chktxc_@plt>
test   %rax,%rax
je     1180 <luart_putc+0x30>
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <luart_puttxd_@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   1070 <luart_settxi_@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @luart_putc(i32 %0, i32 %1) {
%3 = icmp ult i32 %0, 2
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @luart_chktxi_(i32 %0)
%7 = tail call i32 @luart_settxi_(i32 %0, i32 0)
br label %8
8: ; preds = %8, %2
%9 = tail call i64 @luart_chktxc_(i32 %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %8, label %11
11: ; preds = %8
%12 = tail call i32 @luart_puttxd_(i32 %0, i32 %1)
%13 = tail call i32 @luart_settxi_(i32 %0, i32 %6)
ret i32 %12
}