#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 EOF;
int errno;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void show_reserved(FILE *f, char *label, int c) {
  unsigned i;
  printf("%s - %#02x", label, c);
  for (i = 0; (c & 0x80) && i < 4; i++) {
    c = fgetc(f);
    if (c == EOF) {
      printf("(ERROR %d - %s) ", errno, strerror(errno));
      break;
    }
    printf(" %#02x", c);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<show_reserved>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1180 <show_reserved+0x50>
cmpl   $0x4,-0x18(%rbp)
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1190 <show_reserved+0x60>
jmp    1200 <show_reserved+0xd0>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    11e1 <show_reserved+0xb1>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <show_reserved+0xd0>
mov    -0x14(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <show_reserved+0x2f>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_reserved>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r12
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x80,%bpl
je     11d0 <show_reserved+0x90>
mov    0x2e80(%rip),%r15
lea    0xe95(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
je     11ad <show_reserved+0x6d>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x80,%bpl
je     11d0 <show_reserved+0x90>
lea    0x1(%rbx),%eax
cmp    $0x3,%ebx
mov    %eax,%ebx
jb     1180 <show_reserved+0x40>
jmp    11d0 <show_reserved+0x90>
mov    0x2e24(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe47(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%s - %x\00"
@EOF = global i32 0
@.str.1 = [17 x i8] c"(ERROR %d - %s) \00"
@errno = global i32 0
@.str.2 = [7 x i8] c" %x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @show_reserved(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %34, %3
%12 = load i32, i32* %6
%13 = and i32 %12, 128
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %7
%17 = icmp ult i32 %16, 4
br label %18
18: ; preds = %15, %11
%19 = phi i1 [ false, %11 ], [ %17, %15 ]
br i1 %19, label %20, label %37
20: ; preds = %18
%21 = load i32*, i32** %4
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* @errno
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %29)
br label %37
31: ; preds = %20
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
br label %11
37: ; preds = %26, %18
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s - %x\00"
@EOF = global i32 0
@.str.1 = [17 x i8] c"(ERROR %d - %s) \00"
@errno = global i32 0
@.str.2 = [7 x i8] c" %x\00"
define void @show_reserved(i32* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2)
%5 = and i32 %2, 128
%6 = icmp eq i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %3, %16
%8 = phi i32 [ %18, %16 ], [ 0, %3 ]
%9 = tail call i32 @fgetc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %14)
br label %23
16: ; preds = %7
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%18 = add nuw nsw i32 %8, 1
%19 = and i32 %9, 128
%20 = icmp ne i32 %19, 0
%21 = icmp ult i32 %8, 3
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %7, label %23
23: ; preds = %16, %3, %12
%24 = tail call i32 @putchar(i32 10)
ret void
}