#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 sio_read_reg(int, unsigned long *);
int sio_write_reg(int, unsigned long);
int gtlio_pd(int set) {
  int err;
  unsigned long reg;
  err = sio_read_reg(0x30, &reg);
  if (err)
    return err;
  if (set)
    reg |= 0x8000;
  else
    reg &= ~0x8000;
  err = sio_write_reg(0x30, reg);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<gtlio_pd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x30,%edi
lea    -0x18(%rbp),%rsi
call   1040 <sio_read_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1151 <gtlio_pd+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <gtlio_pd+0x89>
cmpl   $0x0,-0x8(%rbp)
je     116e <gtlio_pd+0x4e>
mov    -0x18(%rbp),%rax
or     $0x8000,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <gtlio_pd+0x5c>
mov    -0x18(%rbp),%rax
and    $0xffffffffffff7fff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x30,%edi
call   1030 <sio_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a2 <gtlio_pd+0x82>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <gtlio_pd+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtlio_pd>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x30,%edi
call   1040 <sio_read_reg@plt>
test   %eax,%eax
jne    1164 <gtlio_pd+0x44>
xor    %esi,%esi
test   %ebx,%ebx
setne  %sil
mov    $0xffffffffffff7fff,%rax
and    0x8(%rsp),%rax
shl    $0xf,%rsi
or     %rax,%rsi
mov    %rsi,0x8(%rsp)
mov    $0x30,%edi
call   1030 <sio_write_reg@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @gtlio_pd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
%6 = call i32 @sio_read_reg(i32 48, 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 %28
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %5
%16 = or i64 %15, 32768
store i64 %16, i64* %5
br label %20
17: ; preds = %11
%18 = load i64, i64* %5
%19 = and i64 %18, -32769
store i64 %19, i64* %5
br label %20
20: ; preds = %17, %14
%21 = load i64, i64* %5
%22 = call i32 @sio_write_reg(i32 48, i64 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %28
27: ; preds = %20
store i32 0, i32* %2
br label %28
28: ; preds = %27, %25, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @gtlio_pd(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i32 @sio_read_reg(i32 48, i64* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = icmp eq i32 %0, 0
%8 = load i64, i64* %2
%9 = and i64 %8, -32769
%10 = select i1 %7, i64 0, i64 32768
%11 = or i64 %9, %10
store i64 %11, i64* %2
%12 = call i32 @sio_write_reg(i32 48, i64 %11)
br label %13
13: ; preds = %6, %1
%14 = phi i32 [ %4, %1 ], [ %12, %6 ]
ret i32 %14
}