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

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ conv32network_endian(int *, int);
size_t cmd_read_register(uint32_t **bufio, uint32_t addr) {
  uint32_t *buf;
  buf = *bufio;
  if (buf == NULL) {
    buf = (uint32_t *)calloc(1, sizeof(uint32_t));
    if (buf == NULL)
      return -1;
    *bufio = buf;
  }
  buf[0] = (0xffff0000 & ((0x8020 + addr) << 16));
  conv32network_endian(buf, 1);
  return 1 * sizeof(uint32_t);
}


x86 assembly (clang, -O0):
<cmd_read_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <cmd_read_register+0x5b>
mov    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1170 <cmd_read_register+0x50>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11a9 <cmd_read_register+0x89>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%ecx
add    $0x8020,%ecx
shl    $0x10,%ecx
and    $0xffff0000,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <conv32network_endian@plt>
movq   $0x4,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_read_register>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
jne    114b <cmd_read_register+0x2b>
mov    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     116d <cmd_read_register+0x4d>
mov    %rax,%rdi
mov    %rax,(%r14)
shl    $0x10,%ebx
add    $0x80200000,%ebx
mov    %ebx,(%rdi)
mov    $0x1,%esi
call   1040 <conv32network_endian@plt>
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffffffffffff,%rax
jmp    1165 <cmd_read_register+0x45>

LLVM IR (-O0):
define i64 @cmd_read_register(i32** %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32*
store i32** %0, i32*** %4
store i32 %1, i32* %5
%7 = load i32**, i32*** %4
%8 = load i32*, i32** %7
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = call i64 @calloc(i32 1, i32 4)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i64 -1, i64* %3
br label %29
17: ; preds = %11
%18 = load i32*, i32** %6
%19 = load i32**, i32*** %4
store i32* %18, i32** %19
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* %5
%22 = add nsw i32 32800, %21
%23 = shl i32 %22, 16
%24 = and i32 -65536, %23
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 0
store i32 %24, i32* %26
%27 = load i32*, i32** %6
%28 = call i32 @conv32network_endian(i32* %27, i32 1)
store i64 4, i64* %3
br label %29
29: ; preds = %20, %16
%30 = load i64, i64* %3
ret i64 %30
}

LLVM IR (-O2):
define i64 @cmd_read_register(i32** nocapture %0, i32 %1) {
%3 = load i32*, i32** %0
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i64 @calloc(i32 1, i32 4)
%7 = inttoptr i64 %6 to i32*
%8 = icmp eq i64 %6, 0
br i1 %8, label %15, label %9
9: ; preds = %5
store i32* %7, i32** %0
br label %10
10: ; preds = %9, %2
%11 = phi i32* [ %7, %9 ], [ %3, %2 ]
%12 = shl i32 %1, 16
%13 = add i32 %12, -2145386496
store i32 %13, i32* %11
%14 = tail call i32 @conv32network_endian(i32* %11, i32 1)
br label %15
15: ; preds = %5, %10
%16 = phi i64 [ 4, %10 ], [ -1, %5 ]
ret i64 %16
}