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

/* Variables and functions */
int lowlevel_read(int, int /*<<< orphan*/ *);
int unframe(int /*<<< orphan*/ *, int, struct lux_packet *);
int lux_read(int fd, struct lux_packet *packet) {
  uint8_t rx_buf[2048];
  int r;
  r = lowlevel_read(fd, rx_buf);
  if (r < 0)
    return r;
  r = unframe(rx_buf, r, packet);
  if (r < 0)
    return r;
  return r;
}


x86 assembly (clang, -O0):
<lux_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x2010(%rbp),%rsi
call   1040 <lowlevel_read@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
jge    1162 <lux_read+0x42>
mov    -0x2014(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <lux_read+0x82>
lea    -0x2010(%rbp),%rdi
mov    -0x2014(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <unframe@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
jge    1199 <lux_read+0x79>
mov    -0x2014(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <lux_read+0x82>
mov    -0x2014(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lux_read>:
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%rbx
mov    %rsp,%rsi
call   1040 <lowlevel_read@plt>
test   %eax,%eax
js     1144 <lux_read+0x24>
mov    %rsp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <unframe@plt>
add    $0x2000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.lux_packet = type { i32 }
define i32 @lux_read(i32 %0, %struct.lux_packet* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.lux_packet*
%6 = alloca [2048 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store %struct.lux_packet* %1, %struct.lux_packet** %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [2048 x i32], [2048 x i32]* %6, i64 0, i64 0
%10 = call i32 @lowlevel_read(i32 %8, i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %26
15: ; preds = %2
%16 = getelementptr inbounds [2048 x i32], [2048 x i32]* %6, i64 0, i64 0
%17 = load i32, i32* %7
%18 = load %struct.lux_packet*, %struct.lux_packet** %5
%19 = call i32 @unframe(i32* %16, i32 %17, %struct.lux_packet* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %26
24: ; preds = %15
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %22, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.lux_packet = type { i32 }
define i32 @lux_read(i32 %0, %struct.lux_packet* %1) {
%3 = alloca [2048 x i32]
%4 = bitcast [2048 x i32]* %3 to i8*
%5 = getelementptr inbounds [2048 x i32], [2048 x i32]* %3, i64 0, i64 0
%6 = call i32 @lowlevel_read(i32 %0, i32* %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @unframe(i32* %5, i32 %6, %struct.lux_packet* %1)
br label %10
10: ; preds = %8, %2
%11 = phi i32 [ %6, %2 ], [ %9, %8 ]
ret i32 %11
}