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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ memcpy(int *, char *, int);
int /*<<< orphan*/ nvram_getall(char *, int);
int /*<<< orphan*/ puts_trim_cr(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int do_show(void) {
  char buf[0x10000];
  char *name = buf;
  int size, crc;
  nvram_getall(buf, sizeof(buf));
  memcpy(&crc, buf, 4);
  size = strlen(buf) + 1;
  for (name = buf + strlen(name) + 1; *name; name += strlen(name) + 1) {
    puts_trim_cr(name);
  }
  size = size + (int)name - (int)buf;
  fprintf(stderr, "crc = %x\n", crc);
  fprintf(stderr, "size: %d bytes (%d left)\n", size, 0x10000 - size);
  return 0;
}


x86 assembly (clang, -O0):
<do_show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
lea    -0x10000(%rbp),%rax
mov    %rax,-0x10008(%rbp)
lea    -0x10000(%rbp),%rdi
mov    $0x10000,%esi
call   1070 <nvram_getall@plt>
lea    -0x10000(%rbp),%rsi
lea    -0x10010(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
lea    -0x10000(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1000c(%rbp)
lea    -0x10000(%rbp),%rax
mov    %rax,-0x10018(%rbp)
mov    -0x10008(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10018(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x10008(%rbp)
mov    -0x10008(%rbp),%rax
cmpb   $0x0,(%rax)
je     1221 <do_show+0xd1>
mov    -0x10008(%rbp),%rdi
call   1030 <puts_trim_cr@plt>
mov    -0x10008(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x10008(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10008(%rbp)
jmp    11db <do_show+0x8b>
mov    -0x1000c(%rbp),%eax
mov    -0x10008(%rbp),%rcx
add    %ecx,%eax
lea    -0x10000(%rbp),%rcx
sub    %ecx,%eax
mov    %eax,-0x1000c(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10010(%rbp),%edx
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    -0x1000c(%rbp),%edx
mov    $0x10000,%ecx
sub    -0x1000c(%rbp),%ecx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_show>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10010,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10000,%esi
call   1070 <nvram_getall@plt>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x11,%rbx
cmpb   $0x0,0x11(%rsp,%rax,1)
je     11d7 <do_show+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <puts_trim_cr@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    (%rcx,%rbx,1),%rax
add    $0x1,%rax
cmpb   $0x0,0x1(%rcx,%rbx,1)
mov    %rax,%rbx
jne    11b0 <do_show+0x60>
jmp    11da <do_show+0x8a>
mov    %rbx,%rax
lea    0x10(%rsp),%rcx
sub    %ecx,%r14d
lea    (%r14,%rax,1),%ebp
lea    (%r14,%rax,1),%ebx
add    $0x1,%ebx
mov    0x2dec(%rip),%r14
mov    (%r14),%edi
mov    0xc(%rsp),%edx
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
mov    $0xffff,%ecx
sub    %ebp,%ecx
lea    0xdf0(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [10 x i8] c"crc = %x\0A\00"
@.str.1 = [26 x i8] c"size: %d bytes (%d left)\0A\00"
define i32 @do_show() {
%1 = alloca [65536 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
store i8* %5, i8** %2
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%7 = call i32 @nvram_getall(i8* %6, i32 65536)
%8 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%9 = call i32 @memcpy(i32* %4, i8* %8, i32 4)
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %2
br label %19
19: ; preds = %26, %0
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = call i32 @puts_trim_cr(i8* %24)
br label %26
26: ; preds = %23
%27 = load i8*, i8** %2
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 1
%30 = load i8*, i8** %2
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %2
br label %19
33: ; preds = %19
%34 = load i32, i32* %3
%35 = load i8*, i8** %2
%36 = ptrtoint i8* %35 to i32
%37 = add nsw i32 %34, %36
%38 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%39 = ptrtoint i8* %38 to i32
%40 = sub nsw i32 %37, %39
store i32 %40, i32* %3
%41 = load i32, i32* @stderr
%42 = load i32, i32* %4
%43 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @stderr
%45 = load i32, i32* %3
%46 = load i32, i32* %3
%47 = sub nsw i32 65536, %46
%48 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %47)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [10 x i8] c"crc = %x\0A\00"
@.str.1 = [26 x i8] c"size: %d bytes (%d left)\0A\00"
define i32 @do_show() {
%1 = alloca [65536 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = call i32 @nvram_getall(i8* %3, i32 65536)
%6 = call i32 @memcpy(i32* %2, i8* %3, i32 4)
%7 = call i32 @strlen(i8* %3)
%8 = call i32 @strlen(i8* %3)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %0, %14
%15 = phi i8* [ %20, %14 ], [ %11, %0 ]
%16 = call i32 @puts_trim_cr(i8* %15)
%17 = call i32 @strlen(i8* %15)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %0
%24 = phi i8* [ %11, %0 ], [ %20, %14 ]
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
%27 = ptrtoint [65536 x i8]* %1 to i64
%28 = trunc i64 %27 to i32
%29 = sub i32 1, %28
%30 = add i32 %29, %7
%31 = add i32 %30, %26
%32 = load i32, i32* @stderr
%33 = load i32, i32* %2
%34 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @stderr
%36 = sub nsw i32 65536, %31
%37 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %36)
ret i32 0
}