#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 */
unsigned int dma_get(unsigned int *, int);
int /*<<< orphan*/ dma_mm2s_status(unsigned int *);
int /*<<< orphan*/ dma_s2mm_status(unsigned int *);
int dma_mm2s_sync(unsigned int *dma_virtual_address) {
  unsigned int mm2s_status = dma_get(dma_virtual_address, 0x04);
  while (!(mm2s_status & 1 << 12) || !(mm2s_status & 1 << 1)) {
    dma_s2mm_status(dma_virtual_address);
    dma_mm2s_status(dma_virtual_address);
    mm2s_status = dma_get(dma_virtual_address, 0x04);
  }
}


x86 assembly (clang, -O0):
<dma_mm2s_sync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <dma_get@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
and    $0x1000,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1175 <dma_mm2s_sync+0x45>
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1185 <dma_mm2s_sync+0x55>
jmp    11ad <dma_mm2s_sync+0x7d>
mov    -0x10(%rbp),%rdi
call   1040 <dma_s2mm_status@plt>
mov    -0x10(%rbp),%rdi
call   1030 <dma_mm2s_status@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <dma_get@plt>
mov    %eax,-0x14(%rbp)
jmp    114d <dma_mm2s_sync+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dma_mm2s_sync>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x4,%esi
call   1050 <dma_get@plt>
not    %eax
test   $0x1002,%eax
je     1168 <dma_mm2s_sync+0x38>
mov    %rbx,%rdi
call   1040 <dma_s2mm_status@plt>
mov    %rbx,%rdi
call   1030 <dma_mm2s_status@plt>
mov    %rbx,%rdi
jmp    1140 <dma_mm2s_sync+0x10>
pop    %rbx
ret

LLVM IR (-O0):
define i32 @dma_mm2s_sync(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @dma_get(i32* %5, i32 4)
store i32 %6, i32* %4
br label %7
7: ; preds = %18, %1
%8 = load i32, i32* %4
%9 = and i32 %8, 4096
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %4
%13 = and i32 %12, 2
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ true, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = load i32*, i32** %3
%20 = call i32 @dma_s2mm_status(i32* %19)
%21 = load i32*, i32** %3
%22 = call i32 @dma_mm2s_status(i32* %21)
%23 = load i32*, i32** %3
%24 = call i32 @dma_get(i32* %23, i32 4)
store i32 %24, i32* %4
br label %7
25: ; preds = %16
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @dma_mm2s_sync(i32* %0) {
%2 = tail call i32 @dma_get(i32* %0, i32 4)
%3 = and i32 %2, 4098
%4 = icmp eq i32 %3, 4098
br i1 %4, label %11, label %5
5: ; preds = %1, %5
%6 = tail call i32 @dma_s2mm_status(i32* %0)
%7 = tail call i32 @dma_mm2s_status(i32* %0)
%8 = tail call i32 @dma_get(i32* %0, i32 4)
%9 = and i32 %8, 4098
%10 = icmp eq i32 %9, 4098
br i1 %10, label %11, label %5
11: ; preds = %5, %1
ret i32 undef
}