#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ xmemset(char volatile *, int /*<<< orphan*/, int);
void SecureClearMem(char *Mem, int Size) {
  char *ptr;
  if (!Mem)
    return;
  xmemset((volatile char *)Mem, 0, Size);
  for (ptr = Mem; ptr < (Mem + Size); ptr++) {
    if (*ptr != 0) {
      fprintf(stderr, "LIBUSEFUL ERROR: Failed to clear secure memory");
      exit(3);
    }
  }
}


x86 assembly (clang, -O0):
<SecureClearMem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114f <SecureClearMem+0x1f>
jmp    11c2 <SecureClearMem+0x92>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <xmemset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11c2 <SecureClearMem+0x92>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ac <SecureClearMem+0x7c>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1050 <exit@plt>
jmp    11b1 <SecureClearMem+0x81>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <SecureClearMem+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SecureClearMem>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     115e <SecureClearMem+0x2e>
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <xmemset@plt>
test   %ebp,%ebp
jle    115e <SecureClearMem+0x2e>
movslq %ebp,%rax
add    %rbx,%rax
cmpb   $0x0,(%rbx)
jne    1165 <SecureClearMem+0x35>
add    $0x1,%rbx
cmp    %rax,%rbx
jb     1150 <SecureClearMem+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"LIBUSEFUL ERROR: Failed to clear secure memory\00"
define void @SecureClearMem(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
br label %34
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = call i32 @xmemset(i8* %10, i32 0, i32 %11)
%13 = load i8*, i8** %3
store i8* %13, i8** %5
br label %14
14: ; preds = %31, %9
%15 = load i8*, i8** %5
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = icmp ult i8* %15, %19
br i1 %20, label %21, label %34
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 3)
unreachable
30: ; preds = %21
br label %31
31: ; preds = %30
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
br label %14
34: ; preds = %8, %14
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"LIBUSEFUL ERROR: Failed to clear secure memory\00"
define void @SecureClearMem(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = tail call i32 @xmemset(i8* %0, i32 0, i32 %1)
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = icmp sgt i32 %1, 0
br i1 %8, label %11, label %20
9: ; preds = %11
%10 = icmp ult i8* %15, %7
br i1 %10, label %11, label %20
11: ; preds = %4, %9
%12 = phi i8* [ %15, %9 ], [ %0, %4 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %14, label %9, label %16
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 3)
unreachable
20: ; preds = %9, %4, %2
ret void
}