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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
scalar_t__ glome_derive_key(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int pubkey(int argc, char **argv) {
  uint8_t private_key[32] = {0};
  uint8_t public_key[32] = {0};
  if (fread(private_key, 1, sizeof private_key, stdin) != sizeof private_key) {
    perror("unable to read the private key from stdin");
    return EXIT_FAILURE;
  }
  if (glome_derive_key(private_key, public_key)) {
    fprintf(stderr, "unable to generate a new key\n");
    return EXIT_FAILURE;
  }
  if (fwrite(public_key, 1, sizeof public_key, stdout) != sizeof public_key) {
    perror("unable to write the public key to stdout");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<pubkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x80,%edx
call   1030 <fread@plt>
cltq
cmp    $0x80,%rax
je     11e2 <pubkey+0x82>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127b <pubkey+0x11b>
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1060 <glome_derive_key@plt>
cmp    $0x0,%rax
je     1225 <pubkey+0xc5>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127b <pubkey+0x11b>
lea    -0x110(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x80,%edx
call   1080 <fwrite@plt>
cltq
cmp    $0x80,%rax
je     126f <pubkey+0x10f>
lea    0xdef(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127b <pubkey+0x11b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pubkey>:
sub    $0x108,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
lea    0x80(%rsp),%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1030 <fread@plt>
cmp    $0x80,%eax
jne    124e <pubkey+0xfe>
lea    0x80(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <glome_derive_key@plt>
test   %rax,%rax
je     121b <pubkey+0xcb>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2db7(%rip),%rax
jmp    1244 <pubkey+0xf4>
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1070 <fwrite@plt>
cmp    $0x80,%eax
jne    1257 <pubkey+0x107>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
add    $0x108,%rsp
ret
lea    0xdab(%rip),%rdi
jmp    125e <pubkey+0x10e>
lea    0xdea(%rip),%rdi
call   1060 <perror@plt>
jmp    1212 <pubkey+0xc2>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [42 x i8] c"unable to read the private key from stdin\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"unable to generate a new key\0A\00"
@stdout = global i32 0
@.str.2 = [41 x i8] c"unable to write the public key to stdout\00"
@EXIT_SUCCESS = global i32 0
define i32 @pubkey(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i32]
%7 = alloca [32 x i32]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [32 x i32]* %6 to i8*
%9 = bitcast [32 x i32]* %7 to i8*
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fread(i32* %10, i32 1, i32 128, i32 %11)
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 128
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %38
18: ; preds = %2
%19 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%20 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%21 = call i64 @glome_derive_key(i32* %19, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %38
27: ; preds = %18
%28 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%29 = load i32, i32* @stdout
%30 = call i32 @fwrite(i32* %28, i32 1, i32 128, i32 %29)
%31 = sext i32 %30 to i64
%32 = icmp ne i64 %31, 128
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %38
36: ; preds = %27
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %33, %23, %15
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [42 x i8] c"unable to read the private key from stdin\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"unable to generate a new key\0A\00"
@stdout = global i32 0
@.str.2 = [41 x i8] c"unable to write the public key to stdout\00"
@EXIT_SUCCESS = global i32 0
define i32 @pubkey(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i32]
%4 = alloca [32 x i32]
%5 = bitcast [32 x i32]* %3 to i8*
%6 = bitcast [32 x i32]* %4 to i8*
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fread(i32* %7, i32 1, i32 128, i32 %8)
%10 = icmp eq i32 %9, 128
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %26
13: ; preds = %2
%14 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%15 = call i64 @glome_derive_key(i32* %7, i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %13
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i32* %14, i32 1, i32 128, i32 %21)
%23 = icmp eq i32 %22, 128
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %20, %24, %17, %11
%27 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %20 ]
%28 = load i32, i32* %27
ret i32 %28
}