#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 uint8_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int /*<<< orphan*/ bool_read(int, int *, int);
uint8_t read_twelve_bits_twice(int fd, uint16_t *integers) {
  uint8_t tmp[3];
  if (!bool_read(fd, tmp, sizeof(tmp))) {
    return 0;
  }
  integers[0] = (((uint16_t)tmp[1] & 0x0f) << 8) | tmp[0];
  integers[1] = ((uint16_t)tmp[2] << 4) | ((tmp[1] & 0xf0) >> 4);
  return 1;
}


x86 assembly (clang, -O0):
<read_twelve_bits_twice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0xc,%edx
call   1030 <bool_read@plt>
cmp    $0x0,%eax
jne    1145 <read_twelve_bits_twice+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1178 <read_twelve_bits_twice+0x68>
mov    -0x18(%rbp),%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
or     -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
shl    $0x4,%ecx
mov    -0x18(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_twelve_bits_twice>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rsi
mov    $0xc,%edx
call   1030 <bool_read@plt>
test   %eax,%eax
je     1156 <read_twelve_bits_twice+0x46>
mov    0x8(%rsp),%eax
mov    %eax,%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
or     0x4(%rsp),%ecx
mov    %ecx,(%rbx)
mov    0xc(%rsp),%ecx
shl    $0x4,%ecx
shr    $0x4,%eax
and    $0xf,%eax
or     %ecx,%eax
mov    %eax,0x4(%rbx)
mov    $0x1,%eax
jmp    1158 <read_twelve_bits_twice+0x48>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @read_twelve_bits_twice(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [3 x i32]
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%9 = call i32 @bool_read(i32 %7, i32* %8, i32 12)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %32
12: ; preds = %2
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
%14 = load i32, i32* %13
%15 = and i32 %14, 15
%16 = shl i32 %15, 8
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%18 = load i32, i32* %17
%19 = or i32 %16, %18
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 0
store i32 %19, i32* %21
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
%23 = load i32, i32* %22
%24 = shl i32 %23, 4
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
%26 = load i32, i32* %25
%27 = and i32 %26, 240
%28 = ashr i32 %27, 4
%29 = or i32 %24, %28
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 1
store i32 %29, i32* %31
store i32 1, i32* %3
br label %32
32: ; preds = %12, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @read_twelve_bits_twice(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %3 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%6 = call i32 @bool_read(i32 %0, i32* %5, i32 12)
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%10 = load i32, i32* %9
%11 = shl i32 %10, 8
%12 = and i32 %11, 3840
%13 = load i32, i32* %5
%14 = or i32 %12, %13
store i32 %14, i32* %1
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%16 = load i32, i32* %15
%17 = shl i32 %16, 4
%18 = lshr i32 %10, 4
%19 = and i32 %18, 15
%20 = or i32 %17, %19
%21 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %20, i32* %21
br label %22
22: ; preds = %2, %8
%23 = phi i32 [ 1, %8 ], [ 0, %2 ]
ret i32 %23
}