#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*/ mpz_t;
typedef int /*<<< orphan*/ mpq_t;

/* Variables and functions */
int /*<<< orphan*/ mpq_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpq_div(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpq_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpq_set_z(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_addmul(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_submul(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
void tcos(mpz_t a1, mpz_t a2, mpz_t a3, mpq_t *r) {
  mpz_t nom;
  mpz_t den;
  mpq_t tmp;
  mpz_init(nom);
  mpz_init(den);
  mpq_init(tmp);
  mpz_set_ui(nom, 0);
  mpz_addmul(nom, a1, a1);
  mpz_addmul(nom, a2, a2);
  mpz_submul(nom, a3, a3);
  mpz_set_ui(den, 2);
  mpz_mul(den, den, a1);
  mpz_mul(den, den, a2);
  mpq_set_z(*r, nom);
  mpq_set_z(tmp, den);
  mpq_div(*r, *r, tmp);
  mpz_clear(nom);
  mpz_clear(den);
  mpq_clear(tmp);
}


x86 assembly (clang, -O0):
<tcos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x24(%rbp),%edi
call   1060 <mpq_init@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1090 <mpz_addmul@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1090 <mpz_addmul@plt>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1080 <mpz_submul@plt>
mov    -0x20(%rbp),%edi
mov    $0x2,%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1030 <mpq_set_z@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <mpq_set_z@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
call   10c0 <mpq_div@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   1040 <mpq_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcos>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%ebx
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
call   1060 <mpq_init@plt>
xor    %esi,%esi
call   10a0 <mpz_set_ui@plt>
mov    %ebx,%esi
mov    %ebx,%edx
call   1090 <mpz_addmul@plt>
mov    %ebp,%esi
mov    %ebp,%edx
call   1090 <mpz_addmul@plt>
mov    %r15d,%esi
mov    %r15d,%edx
call   1080 <mpz_submul@plt>
mov    $0x2,%esi
call   10a0 <mpz_set_ui@plt>
mov    %ebx,%edx
call   1070 <mpz_mul@plt>
mov    %ebp,%edx
call   1070 <mpz_mul@plt>
mov    (%r14),%edi
call   1030 <mpq_set_z@plt>
call   1030 <mpq_set_z@plt>
mov    (%r14),%edi
mov    %edi,%esi
call   10c0 <mpq_div@plt>
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mpq_clear@plt>

LLVM IR (-O0):
define void @tcos(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i32, i32* %9
%13 = call i32 @mpz_init(i32 %12)
%14 = load i32, i32* %10
%15 = call i32 @mpz_init(i32 %14)
%16 = load i32, i32* %11
%17 = call i32 @mpq_init(i32 %16)
%18 = load i32, i32* %9
%19 = call i32 @mpz_set_ui(i32 %18, i32 0)
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = call i32 @mpz_addmul(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @mpz_addmul(i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = load i32, i32* %7
%31 = call i32 @mpz_submul(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %10
%33 = call i32 @mpz_set_ui(i32 %32, i32 2)
%34 = load i32, i32* %10
%35 = load i32, i32* %10
%36 = load i32, i32* %5
%37 = call i32 @mpz_mul(i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %10
%39 = load i32, i32* %10
%40 = load i32, i32* %6
%41 = call i32 @mpz_mul(i32 %38, i32 %39, i32 %40)
%42 = load i32*, i32** %8
%43 = load i32, i32* %42
%44 = load i32, i32* %9
%45 = call i32 @mpq_set_z(i32 %43, i32 %44)
%46 = load i32, i32* %11
%47 = load i32, i32* %10
%48 = call i32 @mpq_set_z(i32 %46, i32 %47)
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = load i32*, i32** %8
%52 = load i32, i32* %51
%53 = load i32, i32* %11
%54 = call i32 @mpq_div(i32 %50, i32 %52, i32 %53)
%55 = load i32, i32* %9
%56 = call i32 @mpz_clear(i32 %55)
%57 = load i32, i32* %10
%58 = call i32 @mpz_clear(i32 %57)
%59 = load i32, i32* %11
%60 = call i32 @mpq_clear(i32 %59)
ret void
}

LLVM IR (-O2):
define void @tcos(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpq_init(i32 undef)
%8 = tail call i32 @mpz_set_ui(i32 undef, i32 0)
%9 = tail call i32 @mpz_addmul(i32 undef, i32 %0, i32 %0)
%10 = tail call i32 @mpz_addmul(i32 undef, i32 %1, i32 %1)
%11 = tail call i32 @mpz_submul(i32 undef, i32 %2, i32 %2)
%12 = tail call i32 @mpz_set_ui(i32 undef, i32 2)
%13 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 %0)
%14 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 %1)
%15 = load i32, i32* %3
%16 = tail call i32 @mpq_set_z(i32 %15, i32 undef)
%17 = tail call i32 @mpq_set_z(i32 undef, i32 undef)
%18 = load i32, i32* %3
%19 = tail call i32 @mpq_div(i32 %18, i32 %18, i32 undef)
%20 = tail call i32 @mpz_clear(i32 undef)
%21 = tail call i32 @mpz_clear(i32 undef)
%22 = tail call i32 @mpq_clear(i32 undef)
ret void
}