#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void ses_download_code_sdg(const unsigned char *resp, int resp_len) {
  int k, num_subs;
  unsigned int gen_code;
  const unsigned char *ucp;
  const unsigned char *last_ucp;
  printf("Download microcode status diagnostic page:\n");
  if (resp_len < 4)
    goto truncated;
  num_subs = resp[1] + 1;
  last_ucp = resp + resp_len - 1;
  printf("  number of secondary subenclosures: %d\n", num_subs - 1);
  gen_code = (resp[4] << 24) | (resp[5] << 16) | (resp[6] << 8) | resp[7];
  printf("  generation code: 0x%x\n", gen_code);
  ucp = resp + 8;
  for (k = 0; k < num_subs; ++k, ucp += 16) {
    if ((ucp + 3) > last_ucp)
      goto truncated;
    printf("   subenclosure identifier: %d\n", ucp[1]);
    printf("     download microcode status: 0x%x [additional status: "
           "0x%x]\n",
           ucp[2], ucp[3]);
    printf("     download microcode maximum size: %d bytes\n",
           (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7]);
    printf("     download microcode expected buffer id: 0x%x\n", ucp[11]);
    printf("     download microcode expected buffer id offset: %d\n",
           (ucp[12] << 24) + (ucp[13] << 16) + (ucp[14] << 8) + ucp[15]);
  }
  return;
truncated:
  fprintf(stderr, "    <<<download: response too short>>>\n");
  return;
}


x86 assembly (clang, -O0):
<ses_download_code_sdg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x4,-0xc(%rbp)
jge    114c <ses_download_code_sdg+0x2c>
jmp    12dd <ses_download_code_sdg+0x1bd>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movzbl 0x4(%rax),%eax
shl    $0x18,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d8 <ses_download_code_sdg+0x1b8>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
cmp    -0x28(%rbp),%rax
jbe    11fa <ses_download_code_sdg+0xda>
jmp    12dd <ses_download_code_sdg+0x1bd>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%esi
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%edx
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movzbl 0x4(%rax),%esi
shl    $0x18,%esi
mov    -0x20(%rbp),%rax
movzbl 0x5(%rax),%eax
shl    $0x10,%eax
add    %eax,%esi
mov    -0x20(%rbp),%rax
movzbl 0x6(%rax),%eax
shl    $0x8,%eax
add    %eax,%esi
mov    -0x20(%rbp),%rax
movzbl 0x7(%rax),%eax
add    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movzbl 0xb(%rax),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movzbl 0xc(%rax),%esi
shl    $0x18,%esi
mov    -0x20(%rbp),%rax
movzbl 0xd(%rax),%eax
shl    $0x10,%eax
add    %eax,%esi
mov    -0x20(%rbp),%rax
movzbl 0xe(%rax),%eax
shl    $0x8,%eax
add    %eax,%esi
mov    -0x20(%rbp),%rax
movzbl 0xf(%rax),%eax
add    %eax,%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    11d7 <ses_download_code_sdg+0xb7>
jmp    12f2 <ses_download_code_sdg+0x1d2>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ses_download_code_sdg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x101b(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%r14d
jge    1176 <ses_download_code_sdg+0x46>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xfd8(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>
movzbl 0x1(%rbx),%ebp
mov    %r14d,%eax
lea    (%rbx,%rax,1),%r15
add    $0xffffffffffffffff,%r15
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
bswap  %esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
add    $0xb,%rbx
lea    0xeec(%rip),%r12
lea    0xf15(%rip),%r13
lea    0xf40(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r15,%rbx
ja     1153 <ses_download_code_sdg+0x23>
movzbl -0x2(%rbx),%esi
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl -0x1(%rbx),%esi
movzbl (%rbx),%edx
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1(%rbx),%esi
bswap  %esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x8(%rbx),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x9(%rbx),%esi
bswap  %esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rbx
add    $0xffffffff,%ebp
jne    11d0 <ses_download_code_sdg+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Download microcode status diagnostic page:\0A\00"
@.str.1 = [41 x i8] c" number of secondary subenclosures: %d\0A\00"
@.str.2 = [25 x i8] c" generation code: 0x%x\0A\00"
@.str.3 = [32 x i8] c" subenclosure identifier: %d\0A\00"
@.str.4 = [64 x i8] c" download microcode status: 0x%x [additional status: 0x%x]\0A\00"
@.str.5 = [48 x i8] c" download microcode maximum size: %d bytes\0A\00"
@.str.6 = [50 x i8] c" download microcode expected buffer id: 0x%x\0A\00"
@.str.7 = [55 x i8] c" download microcode expected buffer id offset: %d\0A\00"
@stderr = global i32 0
@.str.8 = [40 x i8] c" <<<download: response too short>>>\0A\00"
define void @ses_download_code_sdg(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %2
br label %136
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -1
store i8* %24, i8** %9
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 24
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl i32 %36, 16
%38 = or i32 %32, %37
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 6
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = shl i32 %42, 8
%44 = or i32 %38, %43
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 7
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = or i32 %44, %48
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 8
store i8* %53, i8** %8
store i32 0, i32* %5
br label %54
54: ; preds = %130, %14
%55 = load i32, i32* %5
%56 = load i32, i32* %6
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %135
58: ; preds = %54
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8*, i8** %9
%62 = icmp ugt i8* %60, %61
br i1 %62, label %63, label %64
63: ; preds = %58
br label %136
64: ; preds = %58
%65 = load i8*, i8** %8
%66 = getelementptr inbounds i8, i8* %65, i64 1
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %68)
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i64 2
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i64 3
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0), i32 %73, i32 %77)
%79 = load i8*, i8** %8
%80 = getelementptr inbounds i8, i8* %79, i64 4
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = shl i32 %82, 24
%84 = load i8*, i8** %8
%85 = getelementptr inbounds i8, i8* %84, i64 5
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = shl i32 %87, 16
%89 = add nsw i32 %83, %88
%90 = load i8*, i8** %8
%91 = getelementptr inbounds i8, i8* %90, i64 6
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = shl i32 %93, 8
%95 = add nsw i32 %89, %94
%96 = load i8*, i8** %8
%97 = getelementptr inbounds i8, i8* %96, i64 7
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = add nsw i32 %95, %99
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %100)
%102 = load i8*, i8** %8
%103 = getelementptr inbounds i8, i8* %102, i64 11
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %105)
%107 = load i8*, i8** %8
%108 = getelementptr inbounds i8, i8* %107, i64 12
%109 = load i8, i8* %108
%110 = zext i8 %109 to i32
%111 = shl i32 %110, 24
%112 = load i8*, i8** %8
%113 = getelementptr inbounds i8, i8* %112, i64 13
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = shl i32 %115, 16
%117 = add nsw i32 %111, %116
%118 = load i8*, i8** %8
%119 = getelementptr inbounds i8, i8* %118, i64 14
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
%122 = shl i32 %121, 8
%123 = add nsw i32 %117, %122
%124 = load i8*, i8** %8
%125 = getelementptr inbounds i8, i8* %124, i64 15
%126 = load i8, i8* %125
%127 = zext i8 %126 to i32
%128 = add nsw i32 %123, %127
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i32 %128)
br label %130
130: ; preds = %64
%131 = load i32, i32* %5
%132 = add nsw i32 %131, 1
store i32 %132, i32* %5
%133 = load i8*, i8** %8
%134 = getelementptr inbounds i8, i8* %133, i64 16
store i8* %134, i8** %8
br label %54
135: ; preds = %54
br label %139
136: ; preds = %63, %13
%137 = load i32, i32* @stderr
%138 = call i32 @fprintf(i32 %137, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %139
139: ; preds = %136, %135
ret void
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c" number of secondary subenclosures: %d\0A\00"
@.str.2 = [25 x i8] c" generation code: 0x%x\0A\00"
@.str.3 = [32 x i8] c" subenclosure identifier: %d\0A\00"
@.str.4 = [64 x i8] c" download microcode status: 0x%x [additional status: 0x%x]\0A\00"
@.str.5 = [48 x i8] c" download microcode maximum size: %d bytes\0A\00"
@.str.6 = [50 x i8] c" download microcode expected buffer id: 0x%x\0A\00"
@.str.7 = [55 x i8] c" download microcode expected buffer id offset: %d\0A\00"
@stderr = global i32 0
@.str.8 = [40 x i8] c" <<<download: response too short>>>\0A\00"
@str = [43 x i8] c"Download microcode status diagnostic page:\00"
define void @ses_download_code_sdg(i8* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%4 = icmp slt i32 %1, 4
br i1 %4, label %94, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = zext i32 %1 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = shl nuw i32 %15, 24
%17 = getelementptr inbounds i8, i8* %0, i64 5
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = shl nuw nsw i32 %19, 16
%21 = or i32 %20, %16
%22 = getelementptr inbounds i8, i8* %0, i64 6
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 8
%26 = or i32 %21, %25
%27 = getelementptr inbounds i8, i8* %0, i64 7
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = or i32 %26, %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i8, i8* %0, i64 8
br label %33
33: ; preds = %5, %38
%34 = phi i32 [ 0, %5 ], [ %91, %38 ]
%35 = phi i8* [ %32, %5 ], [ %92, %38 ]
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = icmp ugt i8* %36, %11
br i1 %37, label %94, label %38
38: ; preds = %33
%39 = getelementptr inbounds i8, i8* %35, i64 1
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i8, i8* %35, i64 2
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = load i8, i8* %36
%47 = zext i8 %46 to i32
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %47)
%49 = getelementptr inbounds i8, i8* %35, i64 4
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = shl nuw i32 %51, 24
%53 = getelementptr inbounds i8, i8* %35, i64 5
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = shl nuw nsw i32 %55, 16
%57 = or i32 %56, %52
%58 = getelementptr inbounds i8, i8* %35, i64 6
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = shl nuw nsw i32 %60, 8
%62 = or i32 %57, %61
%63 = getelementptr inbounds i8, i8* %35, i64 7
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = or i32 %62, %65
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds i8, i8* %35, i64 11
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds i8, i8* %35, i64 12
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = shl nuw i32 %74, 24
%76 = getelementptr inbounds i8, i8* %35, i64 13
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = shl nuw nsw i32 %78, 16
%80 = or i32 %79, %75
%81 = getelementptr inbounds i8, i8* %35, i64 14
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = shl nuw nsw i32 %83, 8
%85 = or i32 %80, %84
%86 = getelementptr inbounds i8, i8* %35, i64 15
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = or i32 %85, %88
%90 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i32 %89)
%91 = add nuw nsw i32 %34, 1
%92 = getelementptr inbounds i8, i8* %35, i64 16
%93 = icmp eq i32 %34, %8
br i1 %93, label %97, label %33
94: ; preds = %33, %2
%95 = load i32, i32* @stderr
%96 = tail call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %97
97: ; preds = %38, %94
ret void
}