#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*/ deb2_impl(unsigned char *, unsigned char **, int, int, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void debruijn2(int _k, unsigned char *_res) {
  unsigned char *p;
  unsigned char *t;
  t = malloc(sizeof(unsigned char) * _k * 2);
  memset(t, 0, sizeof(unsigned char) * _k * 2);
  p = &_res[_k * _k];
  deb2_impl(t, &p, _k, 1, 1);
  free(t);
}


x86 assembly (clang, -O0):
<debruijn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
shl    $0x1,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x4(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    -0x18(%rbp),%rsi
mov    $0x1,%r8d
mov    %r8d,%ecx
call   1040 <deb2_impl@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debruijn2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    (%r15,%r15,1),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    %r15d,%eax
imul   %eax,%eax
add    %r14,%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1040 <deb2_impl@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @debruijn2(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = mul i64 %9, 2
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = mul i64 %16, 2
%18 = trunc i64 %17 to i32
%19 = call i32 @memset(i8* %13, i32 0, i32 %18)
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = load i32, i32* %3
%23 = mul nsw i32 %21, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
store i8* %25, i8** %5
%26 = load i8*, i8** %6
%27 = load i32, i32* %3
%28 = call i32 @deb2_impl(i8* %26, i8** %5, i32 %27, i32 1, i32 1)
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
define void @debruijn2(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = shl i32 %0, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @memset(i8* %6, i32 0, i32 %5)
%8 = mul nsw i32 %0, %0
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8* %10, i8** %3
%11 = call i32 @deb2_impl(i8* %6, i8** %3, i32 %0, i32 1, i32 1)
%12 = call i32 @free(i8* %6)
ret void
}