#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 /*<<< orphan*/ message;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ crypto_box_nistp256aes256gcm(char *, char *,
                                                unsigned long long, char *,
                                                char *, char *);
int /*<<< orphan*/ crypto_box_nistp256aes256gcm_keypair(char *, char *);
scalar_t__ crypto_box_nistp256aes256gcm_open(char *, char *, unsigned long long,
                                             char *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char message[] = "Hello World!\n";
  char *mtext = malloc(sizeof(message) + 16);
  char *ctext = malloc(sizeof(message) + 16);
  unsigned long long mlen = sizeof(message) + 16;
  char pk[64];
  char sk[32];
  char nonce[8];
  bzero(nonce, 8);
  crypto_box_nistp256aes256gcm_keypair(pk, sk);
  memcpy(mtext + 16, message, sizeof(message));
  crypto_box_nistp256aes256gcm(ctext, mtext, mlen, nonce, pk, sk);
  if (crypto_box_nistp256aes256gcm_open(mtext, ctext, mlen, nonce, pk, sk)) {
    printf("Failed!\n");
  } else {
    printf("%s", mtext + 16);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xe75(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xe6f(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    $0x1e,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1e,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1e,-0x30(%rbp)
lea    -0x98(%rbp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <crypto_box_nistp256aes256gcm_keypair@plt>
mov    -0x20(%rbp),%rdi
add    $0x10,%rdi
lea    -0x12(%rbp),%rsi
mov    $0xe,%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    -0x98(%rbp),%rcx
lea    -0x70(%rbp),%r8
lea    -0x90(%rbp),%r9
call   1030 <crypto_box_nistp256aes256gcm@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    -0x98(%rbp),%rcx
lea    -0x70(%rbp),%r8
lea    -0x90(%rbp),%r9
call   1080 <crypto_box_nistp256aes256gcm_open@plt>
cmp    $0x0,%rax
je     125f <main+0xef>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1275 <main+0x105>
mov    -0x20(%rbp),%rsi
add    $0x10,%rsi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movabs $0xa21646c726f57,%rax
mov    %rax,0xe(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x8(%rsp)
mov    $0x1e,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x1e,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0x18(%rsp),%r12
mov    %r12,%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
lea    0x40(%rsp),%r13
lea    0x20(%rsp),%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <crypto_box_nistp256aes256gcm_keypair@plt>
lea    0x10(%rbx),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0xe,%edx
call   1070 <memcpy@plt>
mov    $0x1e,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1030 <crypto_box_nistp256aes256gcm@plt>
mov    $0x1e,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1090 <crypto_box_nistp256aes256gcm_open@plt>
test   %rax,%rax
je     124b <main+0xcb>
lea    0xdcd(%rip),%rdi
call   1050 <puts@plt>
jmp    125c <main+0xdc>
lea    0xdbc(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.message = [14 x i8] c"Hello World!\0A\00"
@.str = [9 x i8] c"Failed!\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [64 x i8]
%7 = alloca [32 x i8]
%8 = alloca [8 x i8]
store i32 0, i32* %1
%9 = bitcast [14 x i8]* %2 to i8*
%10 = call i8* @malloc(i32 30)
store i8* %10, i8** %3
%11 = call i8* @malloc(i32 30)
store i8* %11, i8** %4
store i64 30, i64* %5
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%13 = call i32 @bzero(i8* %12, i32 8)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%16 = call i32 @crypto_box_nistp256aes256gcm_keypair(i8* %14, i8* %15)
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 16
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%20 = call i32 @memcpy(i8* %18, i8* %19, i32 14)
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = load i64, i64* %5
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%27 = call i32 @crypto_box_nistp256aes256gcm(i8* %21, i8* %22, i64 %23, i8* %24, i8* %25, i8* %26)
%28 = load i8*, i8** %3
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%34 = call i64 @crypto_box_nistp256aes256gcm_open(i8* %28, i8* %29, i64 %30, i8* %31, i8* %32, i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %42
38: ; preds = %0
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 16
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %38, %36
ret i32 0
}

LLVM IR (-O2):
@__const.main.message = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@str = [8 x i8] c"Failed!\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [64 x i8]
%3 = alloca [32 x i8]
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%6 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%7 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%11 = call i32 @bzero(i8* %10, i32 8)
%12 = call i32 @crypto_box_nistp256aes256gcm_keypair(i8* %8, i8* %9)
%13 = getelementptr inbounds i8, i8* %6, i64 16
%14 = call i32 @memcpy(i8* %13, i8* %5, i32 14)
%15 = call i32 @crypto_box_nistp256aes256gcm(i8* %7, i8* %6, i64 30, i8* %10, i8* %8, i8* %9)
%16 = call i64 @crypto_box_nistp256aes256gcm_open(i8* %6, i8* %7, i64 30, i8* %10, i8* %8, i8* %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %22
22: ; preds = %20, %18
ret i32 0
}