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

/* Variables and functions */
int read_whitney(int, unsigned long *);
int write_whitney(int, unsigned long);
int PL_adjust_vtotal(int new_vtotal) {
  int err;
  unsigned long reg;
  err = read_whitney(0x6000C, &reg);
  if (err)
    return err;
  reg = ((new_vtotal - 1) << 16) | (0x0000FFFF & reg);
  err = write_whitney(0x6000C, reg);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<PL_adjust_vtotal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x6000c,%edi
lea    -0x18(%rbp),%rsi
call   1040 <read_whitney@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1151 <PL_adjust_vtotal+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <PL_adjust_vtotal+0x7b>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
shl    $0x10,%eax
cltq
mov    -0x18(%rbp),%rcx
and    $0xffff,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x6000c,%edi
call   1030 <write_whitney@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1194 <PL_adjust_vtotal+0x74>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <PL_adjust_vtotal+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PL_adjust_vtotal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x6000c,%edi
call   1040 <read_whitney@plt>
test   %eax,%eax
jne    115d <PL_adjust_vtotal+0x3d>
shl    $0x10,%ebx
add    $0xffff0000,%ebx
movslq %ebx,%rax
movzwl 0x8(%rsp),%esi
or     %rax,%rsi
mov    %rsi,0x8(%rsp)
mov    $0x6000c,%edi
call   1030 <write_whitney@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @PL_adjust_vtotal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
%6 = call i32 @read_whitney(i32 393228, i64* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %26
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = shl i32 %13, 16
%15 = sext i32 %14 to i64
%16 = load i64, i64* %5
%17 = and i64 65535, %16
%18 = or i64 %15, %17
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = call i32 @write_whitney(i32 393228, i64 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %26
25: ; preds = %11
store i32 0, i32* %2
br label %26
26: ; preds = %25, %23, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @PL_adjust_vtotal(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i32 @read_whitney(i32 393228, i64* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = shl i32 %0, 16
%8 = add i32 %7, -65536
%9 = sext i32 %8 to i64
%10 = load i64, i64* %2
%11 = and i64 %10, 65535
%12 = or i64 %11, %9
store i64 %12, i64* %2
%13 = call i32 @write_whitney(i32 393228, i64 %12)
br label %14
14: ; preds = %6, %1
%15 = phi i32 [ %4, %1 ], [ %13, %6 ]
ret i32 %15
}