#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int get_16(int /*<<< orphan*/ *);
int /*<<< orphan*/ get_8(int /*<<< orphan*/ *);
int /*<<< orphan*/ out_16(int);
int /*<<< orphan*/ out_8(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void block(FILE *f) {
  int i, type, length, address;
  type = get_16(f);
  length = get_16(f);
  address = get_16(f);
  fprintf(stderr, "Type %d, length %d, address %04x\n", type, length, address);
  out_16(address);
  out_16(address + length - 1);
  for (i = 0; i < length; i++)
    out_8(get_8(f));
  get_8(f);
}


x86 assembly (clang, -O0):
<block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_16@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1050 <out_16@plt>
mov    -0x18(%rbp),%edi
add    -0x14(%rbp),%edi
sub    $0x1,%edi
call   1050 <out_16@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e6 <block+0x96>
mov    -0x8(%rbp),%rdi
call   1030 <get_8@plt>
mov    %eax,%edi
call   1070 <out_8@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bc <block+0x6c>
mov    -0x8(%rbp),%rdi
call   1030 <get_8@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <get_16@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <get_16@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <get_16@plt>
mov    %eax,%ebp
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <out_16@plt>
lea    (%rbx,%rbp,1),%edi
add    $0xffffffff,%edi
call   1050 <out_16@plt>
test   %ebx,%ebx
jle    11c4 <block+0x74>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <get_8@plt>
mov    %eax,%edi
call   1070 <out_8@plt>
add    $0xffffffff,%ebx
jne    11b0 <block+0x60>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <get_8@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Type %d, length %d, address %04x\0A\00"
define void @block(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @get_16(i32* %7)
store i32 %8, i32* %4
%9 = load i32*, i32** %2
%10 = call i32 @get_16(i32* %9)
store i32 %10, i32* %5
%11 = load i32*, i32** %2
%12 = call i32 @get_16(i32* %11)
store i32 %12, i32* %6
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @out_16(i32 %18)
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = add nsw i32 %20, %21
%23 = sub nsw i32 %22, 1
%24 = call i32 @out_16(i32 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %33, %1
%26 = load i32, i32* %3
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32*, i32** %2
%31 = call i32 @get_8(i32* %30)
%32 = call i32 @out_8(i32 %31)
br label %33
33: ; preds = %29
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %25
36: ; preds = %25
%37 = load i32*, i32** %2
%38 = call i32 @get_8(i32* %37)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Type %d, length %d, address %04x\0A\00"
define void @block(i32* %0) {
%2 = tail call i32 @get_16(i32* %0)
%3 = tail call i32 @get_16(i32* %0)
%4 = tail call i32 @get_16(i32* %0)
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i32 %4)
%7 = tail call i32 @out_16(i32 %4)
%8 = add i32 %3, -1
%9 = add i32 %8, %4
%10 = tail call i32 @out_16(i32 %9)
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %18
12: ; preds = %1, %12
%13 = phi i32 [ %16, %12 ], [ 0, %1 ]
%14 = tail call i32 @get_8(i32* %0)
%15 = tail call i32 @out_8(i32 %14)
%16 = add nuw nsw i32 %13, 1
%17 = icmp eq i32 %16, %3
br i1 %17, label %18, label %12
18: ; preds = %12, %1
%19 = tail call i32 @get_8(i32* %0)
ret void
}