#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 fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int dump_hdr_filter(FILE *in, int type) {
  char buf[1];
  int err;
  if (type == 0) {
  } else if (type == 1)
    printf("===> xtension HDR\n");
  else
    return 1;
  while ((err = fread(buf, sizeof(char), 1, in)) == 1) {
    printf("%c", buf[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<dump_hdr_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113e <dump_hdr_filter+0x1e>
jmp    116c <dump_hdr_filter+0x4c>
cmpl   $0x1,-0x14(%rbp)
jne    115b <dump_hdr_filter+0x3b>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1167 <dump_hdr_filter+0x47>
movl   $0x1,-0x4(%rbp)
jmp    11af <dump_hdr_filter+0x8f>
jmp    116c <dump_hdr_filter+0x4c>
jmp    1171 <dump_hdr_filter+0x51>
lea    -0x15(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jne    11a8 <dump_hdr_filter+0x88>
movsbl -0x15(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1171 <dump_hdr_filter+0x51>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hdr_filter>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %esi,%esi
je     1156 <dump_hdr_filter+0x26>
mov    $0x1,%r14d
cmp    $0x1,%esi
jne    11a4 <dump_hdr_filter+0x74>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
jne    11a4 <dump_hdr_filter+0x74>
lea    0xf(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
je     1180 <dump_hdr_filter+0x50>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"===> xtension HDR\0A\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @dump_hdr_filter(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [1 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %18
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %17
16: ; preds = %11
store i32 1, i32* %3
br label %30
17: ; preds = %14
br label %18
18: ; preds = %17, %10
br label %19
19: ; preds = %24, %18
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i32 @fread(i8* %20, i32 1, i32 1, i32* %21)
store i32 %22, i32* %7
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %19
29: ; preds = %19
store i32 0, i32* %3
br label %30
30: ; preds = %29, %16
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@str = [18 x i8] c"===> xtension HDR\00"
define i32 @dump_hdr_filter(i32* nocapture %0, i32 %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
switch i32 %1, label %16 [
i32 0, label %7
i32 1, label %5
]
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %2, %5
%8 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %7, %10
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = tail call i32 @putchar(i32 %12)
%14 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %10, label %16
16: ; preds = %10, %7, %2
%17 = phi i32 [ 1, %2 ], [ 0, %7 ], [ 0, %10 ]
ret i32 %17
}