#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 */
int driver_read_byte(unsigned char *);
int packet_recv_short(unsigned short *s) {
  int r = 0;
  unsigned char u = 0;
  unsigned char l = 0;
  r = driver_read_byte(&u);
  if (r <= 0)
    return r;
  r = driver_read_byte(&l);
  if (r <= 0)
    return r;
  *s = (unsigned short)(u << 8) | l;
  return r;
}


x86 assembly (clang, -O0):
<packet_recv_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movb   $0x0,-0x16(%rbp)
lea    -0x15(%rbp),%rdi
call   1030 <driver_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     114c <packet_recv_short+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <packet_recv_short+0x7d>
lea    -0x16(%rbp),%rdi
call   1030 <driver_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     116d <packet_recv_short+0x5d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <packet_recv_short+0x7d>
movzbl -0x15(%rbp),%eax
shl    $0x8,%eax
movzwl %ax,%eax
movzbl -0x16(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_recv_short>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
lea    0xf(%rsp),%rdi
call   1030 <driver_read_byte@plt>
test   %eax,%eax
jle    1150 <packet_recv_short+0x40>
lea    0xe(%rsp),%rdi
call   1030 <driver_read_byte@plt>
test   %eax,%eax
jle    1150 <packet_recv_short+0x40>
movzbl 0xf(%rsp),%ecx
shl    $0x8,%ecx
movzbl 0xe(%rsp),%edx
or     %ecx,%edx
mov    %dx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @packet_recv_short(i16* %0) {
%2 = alloca i32
%3 = alloca i16*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
store i16* %0, i16** %3
store i32 0, i32* %4
store i8 0, i8* %5
store i8 0, i8* %6
%7 = call i32 @driver_read_byte(i8* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %30
12: ; preds = %1
%13 = call i32 @driver_read_byte(i8* %6)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %30
18: ; preds = %12
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = shl i32 %20, 8
%22 = trunc i32 %21 to i16
%23 = zext i16 %22 to i32
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = or i32 %23, %25
%27 = trunc i32 %26 to i16
%28 = load i16*, i16** %3
store i16 %27, i16* %28
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %18, %16, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @packet_recv_short(i16* nocapture writeonly %0) {
%2 = alloca i8
%3 = alloca i8
store i8 0, i8* %2
store i8 0, i8* %3
%4 = call i32 @driver_read_byte(i8* %2)
%5 = icmp slt i32 %4, 1
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = call i32 @driver_read_byte(i8* %3)
%8 = icmp slt i32 %7, 1
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = load i8, i8* %2
%11 = zext i8 %10 to i16
%12 = shl nuw i16 %11, 8
%13 = load i8, i8* %3
%14 = zext i8 %13 to i16
%15 = or i16 %12, %14
store i16 %15, i16* %0
br label %16
16: ; preds = %6, %1, %9
%17 = phi i32 [ %7, %9 ], [ %4, %1 ], [ %7, %6 ]
ret i32 %17
}