#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 */
double acos(double);
int /*<<< orphan*/ printf(char *, double);
double sqrt(int);
int main() {
  int a[2];
  int b[2];
  a[0] = 1;
  a[1] = 2;
  b[0] = 1;
  b[1] = 2;
  int dot_product = a[0] * b[0] + a[1] * b[1];
  printf("A B dot product is %d\n", dot_product);
  double a_length = sqrt(a[0] * a[0] + a[1] * a[1]);
  printf("A length is %f\n", a_length);
  double b_length = sqrt(b[0] * b[0] + b[1] * b[1]);
  printf("B length is %f\n", b_length);
  double cosab = dot_product / (a_length * b_length);
  printf("cos A B is %f\n", cosab);
  double ab_angle = acos(cosab);
  printf("A B angle is %f\n", ab_angle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
imul   -0xc(%rbp),%edi
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
add    %eax,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
add    %eax,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xecd(%rip),%rdi
movsd  0xebd(%rip),%xmm0
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0xe6c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <acos@plt>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"A B dot product is %d\0A\00"
@.str.1 = [16 x i8] c"A length is %f\0A\00"
@.str.2 = [16 x i8] c"B length is %f\0A\00"
@.str.3 = [15 x i8] c"cos A B is %f\0A\00"
@.str.4 = [17 x i8] c"A B angle is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 1, i32* %9
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
store i32 2, i32* %10
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 1, i32* %11
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 2, i32* %12
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %14, %16
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = mul nsw i32 %19, %21
%23 = add nsw i32 %17, %22
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = sitofp i32 %24 to double
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%30 = load i32, i32* %29
%31 = mul nsw i32 %28, %30
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%35 = load i32, i32* %34
%36 = mul nsw i32 %33, %35
%37 = add nsw i32 %31, %36
%38 = call double @sqrt(i32 %37)
store double %38, double* %5
%39 = load double, double* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%44 = load i32, i32* %43
%45 = mul nsw i32 %42, %44
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%49 = load i32, i32* %48
%50 = mul nsw i32 %47, %49
%51 = add nsw i32 %45, %50
%52 = call double @sqrt(i32 %51)
store double %52, double* %6
%53 = load double, double* %6
%54 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %53)
%55 = load i32, i32* %4
%56 = sitofp i32 %55 to double
%57 = load double, double* %5
%58 = load double, double* %6
%59 = fmul double %57, %58
%60 = fdiv double %56, %59
store double %60, double* %7
%61 = load double, double* %7
%62 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %61)
%63 = load double, double* %7
%64 = call double @acos(double %63)
store double %64, double* %8
%65 = load double, double* %8
%66 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), double %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"A B dot product is %d\0A\00"
@.str.1 = [16 x i8] c"A length is %f\0A\00"
@.str.2 = [16 x i8] c"B length is %f\0A\00"
@.str.3 = [15 x i8] c"cos A B is %f\0A\00"
@.str.4 = [17 x i8] c"A B angle is %f\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double 5.000000e+00)
%2 = tail call double @sqrt(i32 5)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %2)
%4 = tail call double @sqrt(i32 5)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %4)
%6 = fmul double %2, %4
%7 = fdiv double 5.000000e+00, %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %7)
%9 = tail call double @acos(double %7)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), double %9)
ret i32 0
}