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

/* Variables and functions */
int /*<<< orphan*/ dStrHex(char const *, int, int);
int /*<<< orphan*/ get_pcb_str(int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void show_last_n_deferred_error_page(unsigned char *resp, int len,
                                     int show_pcb) {
  int k, num, pl, pc, pcb;
  unsigned char *ucp;
  char pcb_str[128];
  num = len - 4;
  ucp = &resp[0] + 4;
  if (num < 4) {
    printf("No deferred errors logged\n");
    return;
  }
  printf("Last n deferred errors log page\n");
  for (k = num; k > 0; k -= pl, ucp += pl) {
    if (k < 3) {
      printf("short Last n deferred errors log page\n");
      return;
    }
    pl = ucp[3] + 4;
    pc = (ucp[0] << 8) + ucp[1];
    pcb = ucp[2];
    printf("  Deferred error %d:\n", pc);
    dStrHex((const char *)ucp + 4, pl - 4, 1);
    if (show_pcb) {
      get_pcb_str(pcb, pcb_str, sizeof(pcb_str));
      printf("        <%s>\n", pcb_str);
    }
  }
}


x86 assembly (clang, -O0):
<show_last_n_deferred_error_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1177 <show_last_n_deferred_error_page+0x47>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <show_last_n_deferred_error_page+0x134>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1264 <show_last_n_deferred_error_page+0x134>
cmpl   $0x3,-0x14(%rbp)
jge    11b2 <show_last_n_deferred_error_page+0x82>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <show_last_n_deferred_error_page+0x134>
mov    -0x30(%rbp),%rax
movzbl 0x3(%rax),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x30(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x1c(%rbp),%esi
sub    $0x4,%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
cmpl   $0x0,-0x10(%rbp)
je     123e <show_last_n_deferred_error_page+0x10e>
mov    -0x24(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
call   1050 <get_pcb_str@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1243 <show_last_n_deferred_error_page+0x113>
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    118b <show_last_n_deferred_error_page+0x5b>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_last_n_deferred_error_page>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x7,%esi
jg     1173 <show_last_n_deferred_error_page+0x33>
lea    0xeed(%rip),%rdi
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
add    $0xfffffffc,%ebp
add    $0x4,%rbx
jmp    1198 <show_last_n_deferred_error_page+0x58>
add    %r12,%rbx
sub    %r12d,%ebp
jle    1209 <show_last_n_deferred_error_page+0xc9>
cmp    $0x2,%ebp
jbe    11fd <show_last_n_deferred_error_page+0xbd>
movzbl 0x3(%rbx),%r15d
lea    0x4(%r15),%r12
movzwl (%rbx),%esi
shl    $0x10,%esi
bswap  %esi
movzbl 0x2(%rbx),%r13d
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rbx),%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
test   %r14d,%r14d
je     1190 <show_last_n_deferred_error_page+0x50>
mov    %r13d,%edi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x80,%edx
call   1060 <get_pcb_str@plt>
lea    0xe25(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1190 <show_last_n_deferred_error_page+0x50>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"No deferred errors logged\0A\00"
@.str.1 = [33 x i8] c"Last n deferred errors log page\0A\00"
@.str.2 = [39 x i8] c"short Last n deferred errors log page\0A\00"
@.str.3 = [22 x i8] c" Deferred error %d:\0A\00"
@.str.4 = [14 x i8] c" <%s>\0A\00"
define void @show_last_n_deferred_error_page(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [128 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 4
store i32 %15, i32* %8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 4
store i8* %18, i8** %12
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %78
23: ; preds = %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %8
store i32 %25, i32* %7
br label %26
26: ; preds = %70, %23
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %78
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %78
34: ; preds = %29
%35 = load i8*, i8** %12
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = add nsw i32 %38, 4
store i32 %39, i32* %9
%40 = load i8*, i8** %12
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = shl i32 %43, 8
%45 = load i8*, i8** %12
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = add nsw i32 %44, %48
store i32 %49, i32* %10
%50 = load i8*, i8** %12
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
store i32 %53, i32* %11
%54 = load i32, i32* %10
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load i8*, i8** %12
%57 = getelementptr inbounds i8, i8* %56, i64 4
%58 = load i32, i32* %9
%59 = sub nsw i32 %58, 4
%60 = call i32 @dStrHex(i8* %57, i32 %59, i32 1)
%61 = load i32, i32* %6
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %34
%64 = load i32, i32* %11
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%66 = call i32 @get_pcb_str(i32 %64, i8* %65, i32 128)
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %63, %34
br label %70
70: ; preds = %69
%71 = load i32, i32* %9
%72 = load i32, i32* %7
%73 = sub nsw i32 %72, %71
store i32 %73, i32* %7
%74 = load i32, i32* %9
%75 = load i8*, i8** %12
%76 = sext i32 %74 to i64
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8* %77, i8** %12
br label %26
78: ; preds = %21, %32, %26
ret void
}

LLVM IR (-O2):
@.str.3 = [22 x i8] c" Deferred error %d:\0A\00"
@.str.4 = [14 x i8] c" <%s>\0A\00"
@str = [32 x i8] c"Last n deferred errors log page\00"
@str.5 = [38 x i8] c"short Last n deferred errors log page\00"
@str.6 = [26 x i8] c"No deferred errors logged\00"
define void @show_last_n_deferred_error_page(i8* %0, i32 %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %1, 8
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
br label %46
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%11 = add nsw i32 %1, -4
%12 = getelementptr inbounds i8, i8* %0, i64 4
%13 = icmp eq i32 %2, 0
br label %14
14: ; preds = %9, %41
%15 = phi i8* [ %12, %9 ], [ %44, %41 ]
%16 = phi i32 [ %11, %9 ], [ %42, %41 ]
%17 = icmp ult i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %46
20: ; preds = %14
%21 = getelementptr inbounds i8, i8* %15, i64 3
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = add nuw nsw i32 %23, 4
%25 = load i8, i8* %15
%26 = zext i8 %25 to i32
%27 = shl nuw nsw i32 %26, 8
%28 = getelementptr inbounds i8, i8* %15, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = or i32 %27, %30
%32 = getelementptr inbounds i8, i8* %15, i64 2
%33 = load i8, i8* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%35 = getelementptr inbounds i8, i8* %15, i64 4
%36 = call i32 @dStrHex(i8* %35, i32 %23, i32 1)
br i1 %13, label %41, label %37
37: ; preds = %20
%38 = zext i8 %33 to i32
%39 = call i32 @get_pcb_str(i32 %38, i8* %5, i32 128)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %41
41: ; preds = %20, %37
%42 = sub nsw i32 %16, %24
%43 = zext i32 %24 to i64
%44 = getelementptr inbounds i8, i8* %15, i64 %43
%45 = icmp sgt i32 %42, 0
br i1 %45, label %14, label %46
46: ; preds = %41, %18, %7
ret void
}