#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 uint16_t;

/* Variables and functions */
int st103_get_epreg(int);
int /*<<< orphan*/ st103_set_epreg(int, int);
int /*<<< orphan*/ st103_set_rx_addr(int, int);
int /*<<< orphan*/ st103_set_rx_buf_size(int, int);
int /*<<< orphan*/ st103_set_tx_addr(int, int);
void usb_lld_setup_endpoint(int ep_num, int ep_type, int ep_kind,
                            int ep_rx_addr, int ep_tx_addr,
                            int ep_rx_buf_size) {
  uint16_t epreg_value = st103_get_epreg(ep_num);
  uint16_t ep_rxtx_status = 0;
  epreg_value &= ((0x3000) | (0x0800) | (0x0030) | (0x4000) | (0x0040));
  epreg_value |= ep_type;
  epreg_value |= ep_kind;
  epreg_value |= ep_num;
  if (ep_rx_addr) {
    ep_rxtx_status |= (0x2000);
    st103_set_rx_addr(ep_num, ep_rx_addr);
    st103_set_rx_buf_size(ep_num, ep_rx_buf_size);
  }
  if (ep_tx_addr) {
    ep_rxtx_status |= (0x0020);
    st103_set_tx_addr(ep_num, ep_tx_addr);
  }
  epreg_value ^= ((0x1000) & ep_rxtx_status);
  epreg_value ^= ((0x2000) & ep_rxtx_status);
  epreg_value ^= ((0x0010) & ep_rxtx_status);
  epreg_value ^= ((0x0020) & ep_rxtx_status);
  st103_set_epreg(ep_num, epreg_value);
}


x86 assembly (clang, -O0):
<usb_lld_setup_endpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <st103_get_epreg@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x7870,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11cf <usb_lld_setup_endpoint+0x7f>
mov    -0x20(%rbp),%eax
or     $0x2000,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <st103_set_rx_addr@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <st103_set_rx_buf_size@plt>
cmpl   $0x0,-0x14(%rbp)
je     11ed <usb_lld_setup_endpoint+0x9d>
mov    -0x20(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <st103_set_tx_addr@plt>
mov    -0x20(%rbp),%eax
and    $0x1000,%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0x2000,%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0x10,%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0x20,%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <st103_set_epreg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_lld_setup_endpoint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebx
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,0x4(%rsp)
mov    %esi,%ebp
mov    %edi,%r13d
call   1060 <st103_get_epreg@plt>
mov    %eax,%r15d
test   %r14d,%r14d
je     11d8 <usb_lld_setup_endpoint+0x88>
mov    %r13d,%edi
mov    %r14d,%esi
call   1040 <st103_set_rx_addr@plt>
mov    %r13d,%edi
mov    %ebx,%esi
call   1050 <st103_set_rx_buf_size@plt>
mov    $0x2000,%ebx
test   %r12d,%r12d
je     11a7 <usb_lld_setup_endpoint+0x57>
or     $0x20,%ebx
mov    %r13d,%edi
mov    %r12d,%esi
call   1070 <st103_set_tx_addr@plt>
and    $0x7870,%r15d
or     %r13d,%ebp
or     0x4(%rsp),%ebp
or     %r15d,%ebp
and    $0x2020,%ebx
xor    %ebp,%ebx
mov    %r13d,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <st103_set_epreg@plt>
xor    %ebx,%ebx
test   %r12d,%r12d
jne    1199 <usb_lld_setup_endpoint+0x49>
jmp    11a7 <usb_lld_setup_endpoint+0x57>

LLVM IR (-O0):
define void @usb_lld_setup_endpoint(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%15 = load i32, i32* %7
%16 = call i32 @st103_get_epreg(i32 %15)
store i32 %16, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %13
%18 = and i32 %17, 30832
store i32 %18, i32* %13
%19 = load i32, i32* %8
%20 = load i32, i32* %13
%21 = or i32 %20, %19
store i32 %21, i32* %13
%22 = load i32, i32* %9
%23 = load i32, i32* %13
%24 = or i32 %23, %22
store i32 %24, i32* %13
%25 = load i32, i32* %7
%26 = load i32, i32* %13
%27 = or i32 %26, %25
store i32 %27, i32* %13
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %6
%31 = load i32, i32* %14
%32 = or i32 %31, 8192
store i32 %32, i32* %14
%33 = load i32, i32* %7
%34 = load i32, i32* %10
%35 = call i32 @st103_set_rx_addr(i32 %33, i32 %34)
%36 = load i32, i32* %7
%37 = load i32, i32* %12
%38 = call i32 @st103_set_rx_buf_size(i32 %36, i32 %37)
br label %39
39: ; preds = %30, %6
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* %14
%44 = or i32 %43, 32
store i32 %44, i32* %14
%45 = load i32, i32* %7
%46 = load i32, i32* %11
%47 = call i32 @st103_set_tx_addr(i32 %45, i32 %46)
br label %48
48: ; preds = %42, %39
%49 = load i32, i32* %14
%50 = and i32 4096, %49
%51 = load i32, i32* %13
%52 = xor i32 %51, %50
store i32 %52, i32* %13
%53 = load i32, i32* %14
%54 = and i32 8192, %53
%55 = load i32, i32* %13
%56 = xor i32 %55, %54
store i32 %56, i32* %13
%57 = load i32, i32* %14
%58 = and i32 16, %57
%59 = load i32, i32* %13
%60 = xor i32 %59, %58
store i32 %60, i32* %13
%61 = load i32, i32* %14
%62 = and i32 32, %61
%63 = load i32, i32* %13
%64 = xor i32 %63, %62
store i32 %64, i32* %13
%65 = load i32, i32* %7
%66 = load i32, i32* %13
%67 = call i32 @st103_set_epreg(i32 %65, i32 %66)
ret void
}

LLVM IR (-O2):
define void @usb_lld_setup_endpoint(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @st103_get_epreg(i32 %0)
%8 = icmp eq i32 %3, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @st103_set_rx_addr(i32 %0, i32 %3)
%11 = tail call i32 @st103_set_rx_buf_size(i32 %0, i32 %5)
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ 8192, %9 ], [ 0, %6 ]
%14 = icmp eq i32 %4, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = or i32 %13, 32
%17 = tail call i32 @st103_set_tx_addr(i32 %0, i32 %4)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ %16, %15 ], [ %13, %12 ]
%20 = and i32 %7, 30832
%21 = or i32 %1, %0
%22 = or i32 %21, %2
%23 = or i32 %22, %20
%24 = and i32 %19, 8224
%25 = xor i32 %24, %23
%26 = tail call i32 @st103_set_epreg(i32 %0, i32 %25)
ret void
}