#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
struct zedc_fifo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fifo_pop(struct zedc_fifo *, int /*<<< orphan*/ *);
int fifo_used(struct zedc_fifo *);
int fifo_pop16(struct zedc_fifo *fifo, uint16_t *data) {
  unsigned int i;
  union {
    uint16_t u16;
    uint8_t u8[2];
  } d;
  if (fifo_used(fifo) < 2)
    return 0;
  for (i = 0; i < 4; i++)
    fifo_pop(fifo, &d.u8[i]);
  *data = d.u16;
  return 1;
}


x86 assembly (clang, -O0):
<fifo_pop16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fifo_used@plt>
cmp    $0x2,%eax
jge    114e <fifo_pop16+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1194 <fifo_pop16+0x74>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jae    1184 <fifo_pop16+0x64>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <fifo_pop@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <fifo_pop16+0x35>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifo_pop16>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <fifo_used@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
jl     1175 <fifo_pop16+0x55>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <fifo_pop@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <fifo_pop@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <fifo_pop@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <fifo_pop@plt>
mov    (%rsp),%eax
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.zedc_fifo = type { i32 }
%union.anon = type { [2 x i32] }
define i32 @fifo_pop16(%struct.zedc_fifo* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.zedc_fifo*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %union.anon
store %struct.zedc_fifo* %0, %struct.zedc_fifo** %4
store i32* %1, i32** %5
%8 = load %struct.zedc_fifo*, %struct.zedc_fifo** %4
%9 = call i32 @fifo_used(%struct.zedc_fifo* %8)
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %30
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %23, %12
%14 = load i32, i32* %6
%15 = icmp ult i32 %14, 4
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load %struct.zedc_fifo*, %struct.zedc_fifo** %4
%18 = bitcast %union.anon* %7 to [2 x i32]*
%19 = load i32, i32* %6
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 %20
%22 = call i32 @fifo_pop(%struct.zedc_fifo* %17, i32* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %6
%25 = add i32 %24, 1
store i32 %25, i32* %6
br label %13
26: ; preds = %13
%27 = bitcast %union.anon* %7 to i32*
%28 = load i32, i32* %27
%29 = load i32*, i32** %5
store i32 %28, i32* %29
store i32 1, i32* %3
br label %30
30: ; preds = %26, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.zedc_fifo = type { i32 }
%union.anon = type { [2 x i32] }
define i32 @fifo_pop16(%struct.zedc_fifo* %0, i32* nocapture writeonly %1) {
%3 = alloca %union.anon
%4 = bitcast %union.anon* %3 to i8*
%5 = tail call i32 @fifo_used(%struct.zedc_fifo* %0)
%6 = icmp slt i32 %5, 2
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 0
%9 = call i32 @fifo_pop(%struct.zedc_fifo* %0, i32* %8)
%10 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 1
%11 = call i32 @fifo_pop(%struct.zedc_fifo* %0, i32* %10)
%12 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 2
%13 = call i32 @fifo_pop(%struct.zedc_fifo* %0, i32* %12)
%14 = getelementptr inbounds %union.anon, %union.anon* %3, i64 0, i32 0, i64 3
%15 = call i32 @fifo_pop(%struct.zedc_fifo* %0, i32* %14)
%16 = load i32, i32* %8
store i32 %16, i32* %1
br label %17
17: ; preds = %2, %7
%18 = phi i32 [ 1, %7 ], [ 0, %2 ]
ret i32 %18
}