#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*/ memcpy(void *, void const *, size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void peek(const void *stack, const size_t *count, size_t size, void *data) {
  if (stack == NULL || count == NULL)
    return;
  if (*count == 0)
    return;
  if (data == NULL)
    return;
  memset(data, 0, size);
  memcpy(data, stack + (*count - 1) * size, size);
}


x86 assembly (clang, -O0):
<peek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114e <peek+0x2e>
cmpq   $0x0,-0x10(%rbp)
jne    1153 <peek+0x33>
jmp    11a9 <peek+0x89>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1166 <peek+0x46>
jmp    11a9 <peek+0x89>
cmpq   $0x0,-0x20(%rbp)
jne    1176 <peek+0x56>
jmp    11a9 <peek+0x89>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
sub    $0x1,%rax
imul   -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     117c <peek+0x5c>
mov    %rsi,%r12
test   %rsi,%rsi
je     117c <peek+0x5c>
mov    %rcx,%r15
test   %rcx,%rcx
je     117c <peek+0x5c>
cmpq   $0x0,(%r12)
je     117c <peek+0x5c>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    (%r12),%rax
add    $0xffffffffffffffff,%rax
imul   %r14,%rax
add    %rax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @peek(i8* %0, i64* %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = load i64*, i64** %6
%13 = icmp eq i64* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %4
br label %38
15: ; preds = %11
%16 = load i64*, i64** %6
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %38
20: ; preds = %15
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20
br label %38
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = load i64, i64* %7
%27 = call i32 @memset(i8* %25, i32 0, i64 %26)
%28 = load i8*, i8** %8
%29 = load i8*, i8** %5
%30 = load i64*, i64** %6
%31 = load i64, i64* %30
%32 = sub i64 %31, 1
%33 = load i64, i64* %7
%34 = mul i64 %32, %33
%35 = getelementptr i8, i8* %29, i64 %34
%36 = load i64, i64* %7
%37 = call i32 @memcpy(i8* %28, i8* %35, i64 %36)
br label %38
38: ; preds = %24, %23, %19, %14
ret void
}

LLVM IR (-O2):
define void @peek(i8* %0, i64* %1, i64 %2, i8* %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i64* %1, null
%7 = or i1 %5, %6
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = load i64, i64* %1
%10 = icmp eq i64 %9, 0
%11 = icmp eq i8* %3, null
%12 = or i1 %11, %10
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = tail call i32 @memset(i8* %3, i32 0, i64 %2)
%15 = load i64, i64* %1
%16 = add i64 %15, -1
%17 = mul i64 %16, %2
%18 = getelementptr i8, i8* %0, i64 %17
%19 = tail call i32 @memcpy(i8* %3, i8* %18, i64 %2)
br label %20
20: ; preds = %8, %4, %13
ret void
}