#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 sonic_fifo {
  int dummy;
};

/* Variables and functions */
void *get_write_entry(struct sonic_fifo *);
int /*<<< orphan*/ put_read_entry(struct sonic_fifo *, void *);
int /*<<< orphan*/ put_write_entry(struct sonic_fifo *, void *);
void push_entry(struct sonic_fifo *in_fifo, struct sonic_fifo *out_fifo,
                void *data) {
  void *tdata = data;
  if (out_fifo) {
    tdata = get_write_entry(out_fifo);
    if (!tdata) {
      tdata = data;
      goto out;
    }
    put_write_entry(out_fifo, data);
  }
out:
  put_read_entry(in_fifo, tdata);
}


x86 assembly (clang, -O0):
<push_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <push_entry+0x59>
mov    -0x10(%rbp),%rdi
call   1030 <get_write_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <push_entry+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    118e <push_entry+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <put_write_entry@plt>
jmp    118e <push_entry+0x5e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <put_read_entry@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<push_entry>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r14
test   %rsi,%rsi
je     1164 <push_entry+0x34>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1030 <get_write_entry@plt>
test   %rax,%rax
je     1164 <push_entry+0x34>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <put_write_entry@plt>
mov    %r12,%r15
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <put_read_entry@plt>

LLVM IR (-O0):
%struct.sonic_fifo = type { i32 }
define void @push_entry(%struct.sonic_fifo* %0, %struct.sonic_fifo* %1, i8* %2) {
%4 = alloca %struct.sonic_fifo*
%5 = alloca %struct.sonic_fifo*
%6 = alloca i8*
%7 = alloca i8*
store %struct.sonic_fifo* %0, %struct.sonic_fifo** %4
store %struct.sonic_fifo* %1, %struct.sonic_fifo** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
store i8* %8, i8** %7
%9 = load %struct.sonic_fifo*, %struct.sonic_fifo** %5
%10 = icmp ne %struct.sonic_fifo* %9, null
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load %struct.sonic_fifo*, %struct.sonic_fifo** %5
%13 = call i8* @get_write_entry(%struct.sonic_fifo* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = load i8*, i8** %6
store i8* %17, i8** %7
br label %23
18: ; preds = %11
%19 = load %struct.sonic_fifo*, %struct.sonic_fifo** %5
%20 = load i8*, i8** %6
%21 = call i32 @put_write_entry(%struct.sonic_fifo* %19, i8* %20)
br label %22
22: ; preds = %18, %3
br label %23
23: ; preds = %22, %16
%24 = load %struct.sonic_fifo*, %struct.sonic_fifo** %4
%25 = load i8*, i8** %7
%26 = call i32 @put_read_entry(%struct.sonic_fifo* %24, i8* %25)
ret void
}

LLVM IR (-O2):
%struct.sonic_fifo = type { i32 }
define void @push_entry(%struct.sonic_fifo* %0, %struct.sonic_fifo* %1, i8* %2) {
%4 = icmp eq %struct.sonic_fifo* %1, null
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i8* @get_write_entry(%struct.sonic_fifo* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @put_write_entry(%struct.sonic_fifo* %1, i8* %2)
br label %10
10: ; preds = %5, %3, %8
%11 = phi i8* [ %6, %8 ], [ %2, %3 ], [ %2, %5 ]
%12 = tail call i32 @put_read_entry(%struct.sonic_fifo* %0, i8* %11)
ret void
}