#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 */
int /*<<< orphan*/ ASSERT(int);
int /*<<< orphan*/ _HibernateWriteComplete();
void HibernateTamperIOEnable(uint32_t ui32Input, uint32_t ui32Config) {
  uint32_t ui32Temp, ui32Mask;
  ASSERT(ui32Input < 4);
  ui32Temp = (*((volatile uint32_t *)(0x400FC410)));
  ui32Mask = (ui32Temp & (~((0x00000008 | 0x00000004 | 0x00000002 | 0x00000001)
                            << (ui32Input << 3))));
  ui32Temp = (ui32Mask | ((ui32Config | 0x00000001) << (ui32Input << 3)));
  (*((volatile uint32_t *)(0x400FC360))) = 0xA3359554;
  _HibernateWriteComplete();
  (*((volatile uint32_t *)(0x400FC410))) = ui32Temp;
  _HibernateWriteComplete();
  (*((volatile uint32_t *)(0x400FC360))) = 0;
  _HibernateWriteComplete();
}


x86 assembly (clang, -O0):
<HibernateTamperIOEnable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x4,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <ASSERT@plt>
mov    $0x400fc410,%eax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xf,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%edx
or     $0x1,%edx
mov    -0x4(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x400fc360,%eax
movl   $0xa3359554,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
mov    -0xc(%rbp),%ecx
mov    $0x400fc410,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
mov    $0x400fc360,%eax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1030 <_HibernateWriteComplete@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HibernateTamperIOEnable>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x4,%ebp
setl   %dil
call   1040 <ASSERT@plt>
shl    $0x3,%ebp
mov    $0xf,%eax
mov    %ebp,%ecx
shl    %cl,%eax
not    %eax
or     $0x1,%ebx
shl    %cl,%ebx
and    0x400fc410,%eax
or     %eax,%ebx
movl   $0xa3359554,0x400fc360
54 95 35 a3
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
mov    %ebx,0x400fc410
xor    %eax,%eax
call   1030 <_HibernateWriteComplete@plt>
movl   $0x0,0x400fc360
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <_HibernateWriteComplete@plt>

LLVM IR (-O0):
define void @HibernateTamperIOEnable(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 4
%9 = zext i1 %8 to i32
%10 = call i32 @ASSERT(i32 %9)
%11 = load volatile i32, i32* inttoptr (i64 1074775056 to i32*)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = shl i32 %13, 3
%15 = shl i32 15, %14
%16 = xor i32 %15, -1
%17 = and i32 %12, %16
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = or i32 %19, 1
%21 = load i32, i32* %3
%22 = shl i32 %21, 3
%23 = shl i32 %20, %22
%24 = or i32 %18, %23
store i32 %24, i32* %5
store volatile i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%25 = call i32 (...) @_HibernateWriteComplete()
%26 = load i32, i32* %5
store volatile i32 %26, i32* inttoptr (i64 1074775056 to i32*)
%27 = call i32 (...) @_HibernateWriteComplete()
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
%28 = call i32 (...) @_HibernateWriteComplete()
ret void
}

LLVM IR (-O2):
define void @HibernateTamperIOEnable(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 4
%4 = zext i1 %3 to i32
%5 = tail call i32 @ASSERT(i32 %4)
%6 = load volatile i32, i32* inttoptr (i64 1074775056 to i32*)
%7 = shl i32 %0, 3
%8 = shl i32 15, %7
%9 = xor i32 %8, -1
%10 = and i32 %6, %9
%11 = or i32 %1, 1
%12 = shl i32 %11, %7
%13 = or i32 %10, %12
store volatile i32 -1556769452, i32* inttoptr (i64 1074774880 to i32*)
%14 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 %13, i32* inttoptr (i64 1074775056 to i32*)
%15 = tail call i32 (...) @_HibernateWriteComplete()
store volatile i32 0, i32* inttoptr (i64 1074774880 to i32*)
%16 = tail call i32 (...) @_HibernateWriteComplete()
ret void
}