#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ htonl(scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
void show_tcb(uint32_t *buf, uint32_t len) {
  const char *s;
  int i, n = 8;
  while (len) {
    for (i = 0; len && i < n; i++, buf++, len -= 4) {
      s = i ? " " : "";
      printf("%s%08x", s, htonl(*buf));
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<show_tcb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f2 <show_tcb+0xd2>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x21(%rbp)
je     1165 <show_tcb+0x45>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1175 <show_tcb+0x55>
jmp    11df <show_tcb+0xbf>
mov    -0x1c(%rbp),%edx
lea    0xe8b(%rip),%rax
lea    0xe7a(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <htonl@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <show_tcb+0x29>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1137 <show_tcb+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_tcb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11b0 <show_tcb+0x80>
mov    %rsi,%r12
mov    %rdi,%r14
add    $0xfffffffffffffffc,%r12
lea    0xeb1(%rip),%r15
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    1175 <show_tcb+0x45>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
cmp    %r13,%r12
je     11b0 <show_tcb+0x80>
add    $0x4,%r13
test   %ebp,%ebp
lea    0xe82(%rip),%rbx
lea    0xe7c(%rip),%rax
cmove  %rax,%rbx
mov    (%r14,%r13,2),%rdi
call   1050 <htonl@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13,%r12
je     1160 <show_tcb+0x30>
cmp    $0x6,%ebp
ja     1160 <show_tcb+0x30>
add    $0x1,%ebp
jmp    1171 <show_tcb+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"%s%08x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @show_tcb(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i64* %0, i64** %3
store i64 %1, i64* %4
store i32 8, i32* %7
br label %8
8: ; preds = %38, %2
%9 = load i64, i64* %4
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %40
11: ; preds = %8
store i32 0, i32* %6
br label %12
12: ; preds = %31, %11
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %38
21: ; preds = %19
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = load i64*, i64** %3
%28 = load i64, i64* %27
%29 = call i32 @htonl(i64 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32 %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
%34 = load i64*, i64** %3
%35 = getelementptr inbounds i64, i64* %34, i32 1
store i64* %35, i64** %3
%36 = load i64, i64* %4
%37 = sub nsw i64 %36, 4
store i64 %37, i64* %4
br label %12
38: ; preds = %19
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %8
40: ; preds = %8
ret void
}

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