#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*/ FILE;
typedef int /*<<< orphan*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ BN_bin2bn(unsigned char *, size_t, int /*<<< orphan*/ *);
scalar_t__ BN_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_sqr(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  size_t len;
  unsigned char in[500];
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *x = BN_new();
  BIGNUM *r = BN_new();
  if (argc != 2) {
    printf("no file given\n");
    return -1;
  }
  FILE *f = fopen(argv[1], "rb");
  if (!f) {
    printf("can't open file\n");
    return -1;
  }
  len = fread(in, sizeof(char), 500, f);
  fclose(f);
  BN_bin2bn(in, len, x);
  BN_sqr(r, x, ctx);
  BN_mul(x, x, x, ctx);
  BN_print_fp(stdout, r);
  printf("\n");
  BN_print_fp(stdout, x);
  printf("\n");
  assert(BN_cmp(r, x) == 0);
  BN_free(x);
  BN_free(r);
  BN_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10e0 <BN_CTX_new@plt>
mov    %rax,-0x218(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x220(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x228(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1245 <main+0x65>
lea    0xdcc(%rip),%rdi
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1396 <main+0x1b6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbb(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    1286 <main+0xa6>
lea    0xd9d(%rip),%rdi
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1396 <main+0x1b6>
lea    -0x210(%rbp),%rdi
mov    -0x230(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1f4,%edx
call   1040 <fread@plt>
mov    %rax,-0x18(%rbp)
mov    -0x230(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x210(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x220(%rbp),%rdx
call   1070 <BN_bin2bn@plt>
mov    -0x228(%rbp),%rdi
mov    -0x220(%rbp),%rsi
mov    -0x218(%rbp),%rdx
call   1030 <BN_sqr@plt>
mov    -0x220(%rbp),%rdi
mov    -0x220(%rbp),%rsi
mov    -0x220(%rbp),%rdx
mov    -0x218(%rbp),%rcx
call   10a0 <BN_mul@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
mov    -0x228(%rbp),%rsi
call   10d0 <BN_print_fp@plt>
lea    0xd00(%rip),%rdi
call   1080 <printf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    -0x220(%rbp),%rsi
call   10d0 <BN_print_fp@plt>
lea    0xcdf(%rip),%rdi
call   1080 <printf@plt>
mov    -0x228(%rbp),%rdi
mov    -0x220(%rbp),%rsi
call   10f0 <BN_cmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    -0x220(%rbp),%rdi
call   10b0 <BN_free@plt>
mov    -0x228(%rbp),%rdi
call   10b0 <BN_free@plt>
mov    -0x218(%rbp),%rdi
call   1090 <BN_CTX_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10f0 <BN_CTX_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <BN_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1070 <BN_new@plt>
cmp    $0x2,%ebp
jne    12fd <main+0x10d>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0xdc8(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     1306 <main+0x116>
mov    %rax,%rbx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1f4,%edx
mov    %rax,%rcx
call   1060 <fread@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1080 <fclose@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1090 <BN_bin2bn@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <BN_sqr@plt>
mov    %r12,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   10b0 <BN_mul@plt>
mov    0x2d40(%rip),%rbx
mov    (%rbx),%edi
mov    %r15,%rsi
call   10e0 <BN_print_fp@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rbx),%edi
mov    %r12,%rsi
call   10e0 <BN_print_fp@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1100 <BN_cmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   10d0 <assert@plt>
mov    %r12,%rdi
call   10c0 <BN_free@plt>
mov    %r15,%rdi
call   10c0 <BN_free@plt>
mov    %r14,%rdi
call   10a0 <BN_CTX_free@plt>
xor    %eax,%eax
jmp    1317 <main+0x127>
lea    0xd0f(%rip),%rdi
jmp    130d <main+0x11d>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"no file given\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [17 x i8] c"can't open file\0A\00"
@stdout = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [500 x i8]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* (...) @BN_CTX_new()
store i32* %12, i32** %8
%13 = call i32* (...) @BN_new()
store i32* %13, i32** %9
%14 = call i32* (...) @BN_new()
store i32* %14, i32** %10
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %67
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %11
%24 = load i32*, i32** %11
%25 = icmp ne i32* %24, null
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %67
28: ; preds = %19
%29 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %11
%31 = call i64 @fread(i8* %29, i32 1, i32 500, i32* %30)
store i64 %31, i64* %6
%32 = load i32*, i32** %11
%33 = call i32 @fclose(i32* %32)
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%35 = load i64, i64* %6
%36 = load i32*, i32** %9
%37 = call i32 @BN_bin2bn(i8* %34, i64 %35, i32* %36)
%38 = load i32*, i32** %10
%39 = load i32*, i32** %9
%40 = load i32*, i32** %8
%41 = call i32 @BN_sqr(i32* %38, i32* %39, i32* %40)
%42 = load i32*, i32** %9
%43 = load i32*, i32** %9
%44 = load i32*, i32** %9
%45 = load i32*, i32** %8
%46 = call i32 @BN_mul(i32* %42, i32* %43, i32* %44, i32* %45)
%47 = load i32, i32* @stdout
%48 = load i32*, i32** %10
%49 = call i32 @BN_print_fp(i32 %47, i32* %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @stdout
%52 = load i32*, i32** %9
%53 = call i32 @BN_print_fp(i32 %51, i32* %52)
%54 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32*, i32** %10
%56 = load i32*, i32** %9
%57 = call i64 @BN_cmp(i32* %55, i32* %56)
%58 = icmp eq i64 %57, 0
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i32*, i32** %9
%62 = call i32 @BN_free(i32* %61)
%63 = load i32*, i32** %10
%64 = call i32 @BN_free(i32* %63)
%65 = load i32*, i32** %8
%66 = call i32 @BN_CTX_free(i32* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %28, %26, %17
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@stdout = global i32 0
@str = [16 x i8] c"can't open file\00"
@str.4 = [14 x i8] c"no file given\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = tail call i32* (...) @BN_CTX_new()
%6 = tail call i32* (...) @BN_new()
%7 = tail call i32* (...) @BN_new()
%8 = icmp eq i32 %0, 2
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
br label %37
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %37
18: ; preds = %11
%19 = call i64 @fread(i8* %4, i32 1, i32 500, i32* %14)
%20 = tail call i32 @fclose(i32* %14)
%21 = call i32 @BN_bin2bn(i8* %4, i64 %19, i32* %6)
%22 = call i32 @BN_sqr(i32* %7, i32* %6, i32* %5)
%23 = call i32 @BN_mul(i32* %6, i32* %6, i32* %6, i32* %5)
%24 = load i32, i32* @stdout
%25 = call i32 @BN_print_fp(i32 %24, i32* %7)
%26 = call i32 @putchar(i32 10)
%27 = load i32, i32* @stdout
%28 = call i32 @BN_print_fp(i32 %27, i32* %6)
%29 = call i32 @putchar(i32 10)
%30 = call i64 @BN_cmp(i32* %7, i32* %6)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32 @BN_free(i32* %6)
%35 = call i32 @BN_free(i32* %7)
%36 = call i32 @BN_CTX_free(i32* %5)
br label %37
37: ; preds = %16, %18, %9
%38 = phi i32 [ -1, %9 ], [ 0, %18 ], [ -1, %16 ]
ret i32 %38
}