#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_write_register(uint32_t **bufio, uint32_t addr, uint32_t val) {
  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 & ((0x0020 + addr) << 16)) | (0x0000ffff & val);
  conv32network_endian(buf, 1);
  return 1 * sizeof(uint32_t);
}


x86 assembly (clang, -O0):
<cmd_write_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117e <cmd_write_register+0x5e>
mov    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1173 <cmd_write_register+0x53>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b3 <cmd_write_register+0x93>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%ecx
add    $0x20,%ecx
shl    $0x10,%ecx
and    $0xffff0000,%ecx
mov    -0x18(%rbp),%eax
and    $0xffff,%eax
or     %eax,%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_write_register>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    (%rdi),%rdi
test   %rdi,%rdi
jne    114f <cmd_write_register+0x2f>
mov    $0x1,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1173 <cmd_write_register+0x53>
mov    %rax,%rdi
mov    %rax,0x0(%rbp)
shl    $0x10,%ebx
movzwl %r14w,%eax
add    %ebx,%eax
add    $0x200000,%eax
mov    %eax,(%rdi)
mov    $0x1,%esi
call   1040 <conv32network_endian@plt>
mov    $0x4,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffffffffffff,%rax
jmp    116e <cmd_write_register+0x4e>

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

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