#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 */
scalar_t__ block_read(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
short get_block_ptr(int block) {
  char buffer[4096];
  if (block_read(block, buffer)) {
    fprintf(stderr, "get_block_ptr: Error reading block %d.\n", block);
    return -1;
  }
  short *as_short = (short *)buffer;
  return as_short[0];
}


x86 assembly (clang, -O0):
<get_block_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
call   1040 <block_read@plt>
cmp    $0x0,%rax
je     116a <get_block_ptr+0x4a>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xea6(%rip),%rsi
call   1030 <fprintf@plt>
movw   $0xffff,-0x2(%rbp)
jmp    1186 <get_block_ptr+0x66>
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_block_ptr>:
push   %rbx
sub    $0x1000,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1040 <block_read@plt>
test   %rax,%rax
je     1154 <get_block_ptr+0x34>
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    $0xffff,%ax
jmp    1158 <get_block_ptr+0x38>
movzwl (%rsp),%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"get_block_ptr: Error reading block %d.\0A\00"
define signext i16 @get_block_ptr(i32 %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca i16*
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i64 @block_read(i32 %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12)
store i16 -1, i16* %2
br label %20
14: ; preds = %1
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%16 = bitcast i8* %15 to i16*
store i16* %16, i16** %5
%17 = load i16*, i16** %5
%18 = getelementptr inbounds i16, i16* %17, i64 0
%19 = load i16, i16* %18
store i16 %19, i16* %2
br label %20
20: ; preds = %14, %10
%21 = load i16, i16* %2
ret i16 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"get_block_ptr: Error reading block %d.\0A\00"
define signext i16 @get_block_ptr(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i64 @block_read(i32 %0, i8* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %12
9: ; preds = %1
%10 = bitcast [4096 x i8]* %2 to i16*
%11 = load i16, i16* %10
br label %12
12: ; preds = %9, %6
%13 = phi i16 [ -1, %6 ], [ %11, %9 ]
ret i16 %13
}