#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int big_to_little(int);
int /*<<< orphan*/ printk(char *, ...);
int32_t devicetree_raw_dump(uint32_t *dt_ptr) {
  uint32_t *dt;
  uint32_t magic, size;
  char *ptr;
  int i, count;
  dt = dt_ptr;
  magic = big_to_little(dt[0]);
  if (magic != 0xd00dfeed) {
    return -19;
  }
  size = big_to_little(dt[1]);
  printk("BEGIN DT DUMP OF SIZE %d\n", size);
  count = 0;
  ptr = (char *)dt_ptr;
  for (i = 0; i < size; i++) {
    if ((count & 0xf) == 0)
      printk("\n");
    printk("%d ", ptr[i]);
    count++;
  }
  printk("\nEND DT DUMP\n");
  return 0;
}


x86 assembly (clang, -O0):
<devicetree_raw_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <big_to_little@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xd00dfeed,-0x1c(%rbp)
je     115b <devicetree_raw_dump+0x3b>
movl   $0xffffffed,-0x4(%rbp)
jmp    1200 <devicetree_raw_dump+0xe0>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <big_to_little@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11eb <devicetree_raw_dump+0xcb>
mov    -0x30(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11ba <devicetree_raw_dump+0x9a>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1191 <devicetree_raw_dump+0x71>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devicetree_raw_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    (%rdi),%edi
call   1040 <big_to_little@plt>
mov    $0xffffffed,%r14d
cmp    $0xd00dfeed,%eax
jne    11b8 <devicetree_raw_dump+0x98>
mov    0x4(%r13),%edi
call   1040 <big_to_little@plt>
mov    %eax,%ebp
lea    0xeac(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printk@plt>
test   %ebp,%ebp
jle    11aa <devicetree_raw_dump+0x8a>
mov    %ebp,%ebp
lea    0xebd(%rip),%r15
lea    0xea6(%rip),%r12
xor    %ebx,%ebx
jmp    1199 <devicetree_raw_dump+0x79>
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printk@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11aa <devicetree_raw_dump+0x8a>
test   $0xf,%bl
jne    1180 <devicetree_raw_dump+0x60>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printk@plt>
jmp    1180 <devicetree_raw_dump+0x60>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"BEGIN DT DUMP OF SIZE %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [14 x i8] c"\0AEND DT DUMP\0A\00"
define i32 @devicetree_raw_dump(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
%10 = load i32*, i32** %3
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = call i32 @big_to_little(i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, -804389139
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -19, i32* %2
br label %52
18: ; preds = %1
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
%22 = call i32 @big_to_little(i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 0, i32* %9
%25 = load i32*, i32** %3
%26 = bitcast i32* %25 to i8*
store i8* %26, i8** %7
store i32 0, i32* %8
br label %27
27: ; preds = %47, %18
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %50
31: ; preds = %27
%32 = load i32, i32* %9
%33 = and i32 %32, 15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i8*, i8** %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %47
47: ; preds = %37
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %27
50: ; preds = %27
%51 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %52
52: ; preds = %50, %17
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [26 x i8] c"BEGIN DT DUMP OF SIZE %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [14 x i8] c"\0AEND DT DUMP\0A\00"
define i32 @devicetree_raw_dump(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 @big_to_little(i32 %2)
%4 = icmp eq i32 %3, -804389139
br i1 %4, label %5, label %29
5: ; preds = %1
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @big_to_little(i32 %7)
%9 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = bitcast i32* %0 to i8*
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %27
12: ; preds = %5
%13 = zext i32 %8 to i64
br label %14
14: ; preds = %12, %20
%15 = phi i64 [ 0, %12 ], [ %25, %20 ]
%16 = and i64 %15, 15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = getelementptr inbounds i8, i8* %10, i64 %15
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %15, 1
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %14
27: ; preds = %20, %5
%28 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %1, %27
%30 = phi i32 [ 0, %27 ], [ -19, %1 ]
ret i32 %30
}