#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*/ SYS_getrandom;
int /*<<< orphan*/ aes_128_decrypt(unsigned char *, unsigned char *);
int /*<<< orphan*/ aes_128_encrypt(unsigned char *, unsigned char *);
int /*<<< orphan*/ assert(unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int population_count_u64(unsigned long);
int /*<<< orphan*/ printAESBlock(char *, unsigned char *);
int /*<<< orphan*/ printf(char *, unsigned long, int);
int /*<<< orphan*/ syscall(int /*<<< orphan*/, unsigned char *, int,
                           int /*<<< orphan*/);
int main(void) {
  for (unsigned long i = 0; i < 1024; ++i) {
    if (population_count_u64(i) <= 1)
      printf("popcnt(%lu) = %lu\n", i, population_count_u64(i));
  }
  unsigned char *key = malloc(16);
  assert(key);
  syscall(SYS_getrandom, key, 16, 0);
  unsigned char *data = malloc(16);
  assert(data);
  syscall(SYS_getrandom, data, 16, 0);
  printAESBlock("Key:                    ", key);
  printAESBlock("Data before encryption: ", data);
  aes_128_encrypt(data, key);
  printAESBlock("Data after encryption:  ", data);
  aes_128_decrypt(data, key);
  printAESBlock("Data after decryption:  ", data);
  free(key);
  free(data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x400,-0x10(%rbp)
jae    1200 <main+0x70>
mov    -0x10(%rbp),%rdi
call   10a0 <population_count_u64@plt>
cmp    $0x1,%eax
jg     11ea <main+0x5a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <population_count_u64@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
jmp    11ef <main+0x5f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a7 <main+0x17>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <assert@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <syscall@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <assert@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <syscall@plt>
mov    -0x18(%rbp),%rsi
lea    0xda8(%rip),%rdi
call   1080 <printAESBlock@plt>
mov    -0x20(%rbp),%rsi
lea    0xdb1(%rip),%rdi
call   1080 <printAESBlock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <aes_128_encrypt@plt>
mov    -0x20(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1080 <printAESBlock@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <aes_128_decrypt@plt>
mov    -0x20(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1080 <printAESBlock@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
lea    0xe62(%rip),%r14
jmp    11ad <main+0x1d>
add    $0x1,%rbx
cmp    $0x400,%rbx
je     11d1 <main+0x41>
mov    %rbx,%rdi
call   10a0 <population_count_u64@plt>
cmp    $0x1,%eax
jg     11a0 <main+0x10>
mov    %rbx,%rdi
call   10a0 <population_count_u64@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
jmp    11a0 <main+0x10>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <assert@plt>
mov    0x2dfb(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <syscall@plt>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <syscall@plt>
lea    0xde6(%rip),%rdi
mov    %r14,%rsi
call   1080 <printAESBlock@plt>
lea    0xdf0(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printAESBlock@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <aes_128_encrypt@plt>
lea    0xdef(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printAESBlock@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <aes_128_decrypt@plt>
lea    0xdee(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printAESBlock@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"popcnt(%lu) = %lu\0A\00"
@SYS_getrandom = global i32 0
@.str.1 = [25 x i8] c"Key: \00"
@.str.2 = [25 x i8] c"Data before encryption: \00"
@.str.3 = [25 x i8] c"Data after encryption: \00"
@.str.4 = [25 x i8] c"Data after decryption: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i64 0, i64* %2
br label %5
5: ; preds = %18, %0
%6 = load i64, i64* %2
%7 = icmp ult i64 %6, 1024
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i64, i64* %2
%10 = call i32 @population_count_u64(i64 %9)
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i64, i64* %2
%14 = load i64, i64* %2
%15 = call i32 @population_count_u64(i64 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %13, i32 %15)
br label %17
17: ; preds = %12, %8
br label %18
18: ; preds = %17
%19 = load i64, i64* %2
%20 = add i64 %19, 1
store i64 %20, i64* %2
br label %5
21: ; preds = %5
%22 = call i8* @malloc(i32 16)
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @assert(i8* %23)
%25 = load i32, i32* @SYS_getrandom
%26 = load i8*, i8** %3
%27 = call i32 @syscall(i32 %25, i8* %26, i32 16, i32 0)
%28 = call i8* @malloc(i32 16)
store i8* %28, i8** %4
%29 = load i8*, i8** %4
%30 = call i32 @assert(i8* %29)
%31 = load i32, i32* @SYS_getrandom
%32 = load i8*, i8** %4
%33 = call i32 @syscall(i32 %31, i8* %32, i32 16, i32 0)
%34 = load i8*, i8** %3
%35 = call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %4
%37 = call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = call i32 @aes_128_encrypt(i8* %38, i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %4
%44 = load i8*, i8** %3
%45 = call i32 @aes_128_decrypt(i8* %43, i8* %44)
%46 = load i8*, i8** %4
%47 = call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %3
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %4
%51 = call i32 @free(i8* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"popcnt(%lu) = %lu\0A\00"
@SYS_getrandom = global i32 0
@.str.1 = [25 x i8] c"Key: \00"
@.str.2 = [25 x i8] c"Data before encryption: \00"
@.str.3 = [25 x i8] c"Data after encryption: \00"
@.str.4 = [25 x i8] c"Data after decryption: \00"
define i32 @main() {
br label %18
1: ; preds = %25
%2 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%3 = tail call i32 @assert(i8* %2)
%4 = load i32, i32* @SYS_getrandom
%5 = tail call i32 @syscall(i32 %4, i8* %2, i32 16, i32 0)
%6 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%7 = tail call i32 @assert(i8* %6)
%8 = load i32, i32* @SYS_getrandom
%9 = tail call i32 @syscall(i32 %8, i8* %6, i32 16, i32 0)
%10 = tail call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%11 = tail call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%12 = tail call i32 @aes_128_encrypt(i8* %6, i8* %2)
%13 = tail call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%14 = tail call i32 @aes_128_decrypt(i8* %6, i8* %2)
%15 = tail call i32 @printAESBlock(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%16 = tail call i32 @free(i8* %2)
%17 = tail call i32 @free(i8* %6)
ret i32 0
18: ; preds = %0, %25
%19 = phi i64 [ 0, %0 ], [ %26, %25 ]
%20 = tail call i32 @population_count_u64(i64 %19)
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 @population_count_u64(i64 %19)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %19, i32 %23)
br label %25
25: ; preds = %18, %22
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, 1024
br i1 %27, label %1, label %18
}