#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 */
struct IsdnCardState {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ UART_IIR;
int UART_IIR_NO_INT;
int /*<<< orphan*/ UART_LSR;
int UART_LSR_DR;
int UART_LSR_THRE;
int /*<<< orphan*/ UART_MSR;
int /*<<< orphan*/ debugl1(struct IsdnCardState *, char *, int);
int /*<<< orphan*/ printk(char *);
int /*<<< orphan*/ receive_chars(struct IsdnCardState *, int *);
int serial_inp(struct IsdnCardState *, int /*<<< orphan*/);
int /*<<< orphan*/ transmit_chars(struct IsdnCardState *, int /*<<< orphan*/);
void rs_interrupt_elsa(int irq, struct IsdnCardState *cs) {
  int status, iir, msr;
  int pass_counter = 0;
  do {
    status = serial_inp(cs, UART_LSR);
    debugl1(cs, "rs LSR %02x", status);
    if (status & UART_LSR_DR)
      receive_chars(cs, &status);
    if (status & UART_LSR_THRE)
      transmit_chars(cs, 0);
    if (pass_counter++ > 256) {
      printk("rs_single loop break.\n");
      break;
    }
    iir = serial_inp(cs, UART_IIR);
    debugl1(cs, "rs IIR %02x", iir);
    if ((iir & 0xf) == 0) {
      msr = serial_inp(cs, UART_MSR);
      debugl1(cs, "rs MSR %02x", msr);
    }
  } while (!(iir & UART_IIR_NO_INT));
}


x86 assembly (clang, -O0):
<rs_interrupt_elsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1070 <serial_inp@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe77(%rip),%rsi
call   1050 <debugl1@plt>
mov    -0x14(%rbp),%eax
mov    0x2e50(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b0 <rs_interrupt_elsa+0x60>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <receive_chars@plt>
mov    -0x14(%rbp),%eax
mov    0x2e26(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11d0 <rs_interrupt_elsa+0x80>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <transmit_chars@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x100,%eax
jle    11f7 <rs_interrupt_elsa+0xa7>
lea    0xe1f(%rip),%rdi
call   1030 <printk@plt>
jmp    1277 <rs_interrupt_elsa+0x127>
mov    -0x10(%rbp),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
call   1070 <serial_inp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe09(%rip),%rsi
call   1050 <debugl1@plt>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1256 <rs_interrupt_elsa+0x106>
mov    -0x10(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
call   1070 <serial_inp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xdde(%rip),%rsi
call   1050 <debugl1@plt>
jmp    125b <rs_interrupt_elsa+0x10b>
mov    -0x18(%rbp),%eax
mov    0x2d6b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <rs_interrupt_elsa+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rs_interrupt_elsa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x102,%r12d
mov    0x2e75(%rip),%r13
lea    0xeb1(%rip),%r15
mov    0x2e57(%rip),%r14
jmp    1189 <rs_interrupt_elsa+0x39>
nopl   0x0(%rax,%rax,1)
test   %ebp,(%r14)
jne    1242 <rs_interrupt_elsa+0xf2>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <serial_inp@plt>
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
lea    0xe58(%rip),%rsi
mov    %eax,%edx
call   1050 <debugl1@plt>
mov    0x4(%rsp),%eax
mov    0x2e2e(%rip),%rcx
test   %eax,(%rcx)
je     11cf <rs_interrupt_elsa+0x7f>
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
call   1040 <receive_chars@plt>
mov    0x4(%rsp),%eax
test   %eax,0x0(%r13)
je     11df <rs_interrupt_elsa+0x8f>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <transmit_chars@plt>
add    $0xffffffff,%r12d
je     1236 <rs_interrupt_elsa+0xe6>
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <serial_inp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <debugl1@plt>
test   $0xf,%bpl
jne    1180 <rs_interrupt_elsa+0x30>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <serial_inp@plt>
mov    %rbx,%rdi
lea    0xe05(%rip),%rsi
mov    %eax,%edx
call   1050 <debugl1@plt>
jmp    1180 <rs_interrupt_elsa+0x30>
lea    0xdcf(%rip),%rdi
call   1030 <printk@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.IsdnCardState = type { i32 }
@UART_LSR = global i32 0
@.str = [12 x i8] c"rs LSR %02x\00"
@UART_LSR_DR = global i32 0
@UART_LSR_THRE = global i32 0
@.str.1 = [23 x i8] c"rs_single loop break.\0A\00"
@UART_IIR = global i32 0
@.str.2 = [12 x i8] c"rs IIR %02x\00"
@UART_MSR = global i32 0
@.str.3 = [12 x i8] c"rs MSR %02x\00"
@UART_IIR_NO_INT = global i32 0
define void @rs_interrupt_elsa(i32 %0, %struct.IsdnCardState* %1) {
%3 = alloca i32
%4 = alloca %struct.IsdnCardState*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store %struct.IsdnCardState* %1, %struct.IsdnCardState** %4
store i32 0, i32* %8
br label %9
9: ; preds = %55, %2
%10 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%11 = load i32, i32* @UART_LSR
%12 = call i32 @serial_inp(%struct.IsdnCardState* %10, i32 %11)
store i32 %12, i32* %5
%13 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%14 = load i32, i32* %5
%15 = call i32 @debugl1(%struct.IsdnCardState* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = load i32, i32* @UART_LSR_DR
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %9
%21 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%22 = call i32 @receive_chars(%struct.IsdnCardState* %21, i32* %5)
br label %23
23: ; preds = %20, %9
%24 = load i32, i32* %5
%25 = load i32, i32* @UART_LSR_THRE
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%30 = call i32 @transmit_chars(%struct.IsdnCardState* %29, i32 0)
br label %31
31: ; preds = %28, %23
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = icmp sgt i32 %32, 256
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @printk(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %61
37: ; preds = %31
%38 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%39 = load i32, i32* @UART_IIR
%40 = call i32 @serial_inp(%struct.IsdnCardState* %38, i32 %39)
store i32 %40, i32* %6
%41 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%42 = load i32, i32* %6
%43 = call i32 @debugl1(%struct.IsdnCardState* %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = and i32 %44, 15
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %37
%48 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%49 = load i32, i32* @UART_MSR
%50 = call i32 @serial_inp(%struct.IsdnCardState* %48, i32 %49)
store i32 %50, i32* %7
%51 = load %struct.IsdnCardState*, %struct.IsdnCardState** %4
%52 = load i32, i32* %7
%53 = call i32 @debugl1(%struct.IsdnCardState* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %47, %37
br label %55
55: ; preds = %54
%56 = load i32, i32* %6
%57 = load i32, i32* @UART_IIR_NO_INT
%58 = and i32 %56, %57
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br i1 %60, label %9, label %61
61: ; preds = %55, %35
ret void
}

LLVM IR (-O2):
%struct.IsdnCardState = type { i32 }
@UART_LSR = global i32 0
@.str = [12 x i8] c"rs LSR %02x\00"
@UART_LSR_DR = global i32 0
@UART_LSR_THRE = global i32 0
@.str.1 = [23 x i8] c"rs_single loop break.\0A\00"
@UART_IIR = global i32 0
@.str.2 = [12 x i8] c"rs IIR %02x\00"
@UART_MSR = global i32 0
@.str.3 = [12 x i8] c"rs MSR %02x\00"
@UART_IIR_NO_INT = global i32 0
define void @rs_interrupt_elsa(i32 %0, %struct.IsdnCardState* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %39, %2
%6 = phi i32 [ 0, %2 ], [ %25, %39 ]
%7 = load i32, i32* @UART_LSR
%8 = call i32 @serial_inp(%struct.IsdnCardState* %1, i32 %7)
store i32 %8, i32* %3
%9 = call i32 @debugl1(%struct.IsdnCardState* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
%11 = load i32, i32* @UART_LSR_DR
%12 = and i32 %11, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = call i32 @receive_chars(%struct.IsdnCardState* %1, i32* %3)
%16 = load i32, i32* %3
br label %17
17: ; preds = %14, %5
%18 = phi i32 [ %16, %14 ], [ %10, %5 ]
%19 = load i32, i32* @UART_LSR_THRE
%20 = and i32 %19, %18
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 @transmit_chars(%struct.IsdnCardState* %1, i32 0)
br label %24
24: ; preds = %22, %17
%25 = add nuw nsw i32 %6, 1
%26 = icmp eq i32 %6, 257
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @printk(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %43
29: ; preds = %24
%30 = load i32, i32* @UART_IIR
%31 = call i32 @serial_inp(%struct.IsdnCardState* %1, i32 %30)
%32 = call i32 @debugl1(%struct.IsdnCardState* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = and i32 %31, 15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i32, i32* @UART_MSR
%37 = call i32 @serial_inp(%struct.IsdnCardState* %1, i32 %36)
%38 = call i32 @debugl1(%struct.IsdnCardState* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %29, %35
%40 = load i32, i32* @UART_IIR_NO_INT
%41 = and i32 %40, %31
%42 = icmp eq i32 %41, 0
br i1 %42, label %5, label %43
43: ; preds = %39, %27
ret void
}