#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 */
uint32_t EEPROMBlockUnlock(uint32_t ui32Block, uint32_t *pui32Password,
                           uint32_t ui32Count) {
  ;
  ;
  ;
  (*((volatile unsigned long *)(0x400AF004))) = ui32Block;
  (*((volatile unsigned long *)(0x400AF020))) = 0xFFFFFFFF;
  pui32Password += (ui32Count - 1);
  while (ui32Count) {
    (*((volatile unsigned long *)(0x400AF020))) = *pui32Password--;
    ui32Count--;
  }
  return ((*((volatile unsigned long *)(0x400AF020))));
}


x86 assembly (clang, -O0):
<EEPROMBlockUnlock>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x4(%rbp),%rcx
mov    $0x400af004,%eax
mov    %rcx,(%rax)
mov    $0x400af020,%eax
mov    $0xffffffff,%ecx
mov    %rcx,(%rax)
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1171 <EEPROMBlockUnlock+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x10(%rbp)
movslq (%rax),%rcx
mov    $0x400af020,%eax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <EEPROMBlockUnlock+0x3f>
mov    $0x400af020,%eax
mov    (%rax),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROMBlockUnlock>:
movslq %edi,%rax
mov    %rax,0x400af004
40
mov    $0xffffffff,%eax
mov    %rax,0x400af020
40
test   %edx,%edx
je     11df <EEPROMBlockUnlock+0xdf>
lea    -0x1(%rdx),%r8d
movslq %r8d,%rax
lea    (%rsi,%rax,4),%rax
mov    %edx,%esi
and    $0x7,%esi
je     1158 <EEPROMBlockUnlock+0x58>
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq (%rax),%rcx
add    $0xfffffffffffffffc,%rax
mov    %rcx,0x400af020
40
add    $0x1,%edi
cmp    %edi,%esi
jne    1140 <EEPROMBlockUnlock+0x40>
sub    %edi,%edx
cmp    $0x7,%r8d
jb     11df <EEPROMBlockUnlock+0xdf>
neg    %edx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movslq (%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x4(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x8(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0xc(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x10(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x14(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x18(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
movslq -0x1c(%rax,%rcx,4),%rsi
mov    %rsi,0x400af020
40
add    $0xfffffffffffffff8,%rcx
cmp    %ecx,%edx
jne    1170 <EEPROMBlockUnlock+0x70>
mov    0x400af020,%rax
40
ret

LLVM IR (-O0):
define i32 @EEPROMBlockUnlock(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
store volatile i64 %8, i64* inttoptr (i64 1074458628 to i64*)
store volatile i64 4294967295, i64* inttoptr (i64 1074458656 to i64*)
%9 = load i32, i32* %6
%10 = sub nsw i32 %9, 1
%11 = load i32*, i32** %5
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i32, i32* %11, i64 %12
store i32* %13, i32** %5
br label %14
14: ; preds = %17, %3
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i32 -1
store i32* %19, i32** %5
%20 = load i32, i32* %18
%21 = sext i32 %20 to i64
store volatile i64 %21, i64* inttoptr (i64 1074458656 to i64*)
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
br label %14
24: ; preds = %14
%25 = load volatile i64, i64* inttoptr (i64 1074458656 to i64*)
%26 = trunc i64 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
define i32 @EEPROMBlockUnlock(i32 %0, i32* nocapture %1, i32 %2) {
%4 = sext i32 %0 to i64
store volatile i64 %4, i64* inttoptr (i64 1074458628 to i64*)
store volatile i64 4294967295, i64* inttoptr (i64 1074458656 to i64*)
%5 = icmp eq i32 %2, 0
br i1 %5, label %56, label %6
6: ; preds = %3
%7 = add nsw i32 %2, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = add i32 %2, -1
%11 = and i32 %2, 7
%12 = icmp eq i32 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %6, %13
%14 = phi i32 [ %20, %13 ], [ %2, %6 ]
%15 = phi i32* [ %17, %13 ], [ %9, %6 ]
%16 = phi i32 [ %21, %13 ], [ 0, %6 ]
%17 = getelementptr inbounds i32, i32* %15, i64 -1
%18 = load i32, i32* %15
%19 = sext i32 %18 to i64
store volatile i64 %19, i64* inttoptr (i64 1074458656 to i64*)
%20 = add nsw i32 %14, -1
%21 = add i32 %16, 1
%22 = icmp eq i32 %21, %11
br i1 %22, label %23, label %13
23: ; preds = %13, %6
%24 = phi i32 [ %2, %6 ], [ %20, %13 ]
%25 = phi i32* [ %9, %6 ], [ %17, %13 ]
%26 = icmp ult i32 %10, 7
br i1 %26, label %56, label %27
27: ; preds = %23, %27
%28 = phi i32 [ %54, %27 ], [ %24, %23 ]
%29 = phi i32* [ %51, %27 ], [ %25, %23 ]
%30 = getelementptr inbounds i32, i32* %29, i64 -1
%31 = load i32, i32* %29
%32 = sext i32 %31 to i64
store volatile i64 %32, i64* inttoptr (i64 1074458656 to i64*)
%33 = getelementptr inbounds i32, i32* %29, i64 -2
%34 = load i32, i32* %30
%35 = sext i32 %34 to i64
store volatile i64 %35, i64* inttoptr (i64 1074458656 to i64*)
%36 = getelementptr inbounds i32, i32* %29, i64 -3
%37 = load i32, i32* %33
%38 = sext i32 %37 to i64
store volatile i64 %38, i64* inttoptr (i64 1074458656 to i64*)
%39 = getelementptr inbounds i32, i32* %29, i64 -4
%40 = load i32, i32* %36
%41 = sext i32 %40 to i64
store volatile i64 %41, i64* inttoptr (i64 1074458656 to i64*)
%42 = getelementptr inbounds i32, i32* %29, i64 -5
%43 = load i32, i32* %39
%44 = sext i32 %43 to i64
store volatile i64 %44, i64* inttoptr (i64 1074458656 to i64*)
%45 = getelementptr inbounds i32, i32* %29, i64 -6
%46 = load i32, i32* %42
%47 = sext i32 %46 to i64
store volatile i64 %47, i64* inttoptr (i64 1074458656 to i64*)
%48 = getelementptr inbounds i32, i32* %29, i64 -7
%49 = load i32, i32* %45
%50 = sext i32 %49 to i64
store volatile i64 %50, i64* inttoptr (i64 1074458656 to i64*)
%51 = getelementptr inbounds i32, i32* %29, i64 -8
%52 = load i32, i32* %48
%53 = sext i32 %52 to i64
store volatile i64 %53, i64* inttoptr (i64 1074458656 to i64*)
%54 = add nsw i32 %28, -8
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %27
56: ; preds = %23, %27, %3
%57 = load volatile i64, i64* inttoptr (i64 1074458656 to i64*)
%58 = trunc i64 %57 to i32
ret i32 %58
}