#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 */
int /*<<< orphan*/ printf(char *, ...);
int sqrt(int);
int main() {
  int side1, side2, side3, allSidesDiv2, area;
  side1 = 3;
  side2 = 4;
  side3 = 5;
  printf("\nUsing Heron's formula we are going to find the area of a\ntriangle "
         "with the sides of %d, %d, and %d \n",
         side1, side2, side3);
  printf("Heron\'s formula is area = sqrt(s*(s-a)*(s-b)*(s-c)),\nwhere "
         "s=(a+b+c)/2.\n\n");
  allSidesDiv2 = (side1 + side2 + side3) / 2;
  printf("Our triangle calcuates s=(%d+%d+%d)/2 so s=%d.\n", side1, side2,
         side3, allSidesDiv2);
  area = sqrt((allSidesDiv2 - side1) * (allSidesDiv2 - side2) *
              (allSidesDiv2 - side3));
  printf("The area then is, sqrt((%d-%d)*(%d-%d)*(%d-%d) \nwhich equals %d "
         "sqft.\n",
         allSidesDiv2, side1, allSidesDiv2, side2, allSidesDiv2, side3, area);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
movl   $0x5,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
sub    -0x8(%rbp),%edi
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
imul   %eax,%edi
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   %eax,%edi
call   1040 <sqrt@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x10(%rbp),%r10d
mov    -0x18(%rbp),%eax
lea    0xf09(%rip),%rdi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x5,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf88(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x5,%ecx
mov    $0x6,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x6,%edi
call   1050 <sqrt@plt>
mov    %eax,%r10d
lea    0xf05(%rip),%rdi
mov    $0x6,%esi
mov    $0x3,%edx
mov    $0x6,%ecx
mov    $0x4,%r8d
mov    $0x6,%r9d
xor    %eax,%eax
push   %r10
push   $0x5
call   1040 <printf@plt>
add    $0x10,%rsp
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [102 x i8] c"\0AUsing Heron's formula we are going to find the area of a\0Atriangle with the sides of %d, %d, and %d \0A\00"
@.str.1 = [74 x i8] c"Heron's formula is area = sqrt(s*(s-a)*(s-b)*(s-c)),\0Awhere s=(a+b+c)/2.\0A\0A\00"
@.str.2 = [48 x i8] c"Our triangle calcuates s=(%d+%d+%d)/2 so s=%d.\0A\00"
@.str.3 = [71 x i8] c"The area then is, sqrt((%d-%d)*(%d-%d)*(%d-%d) \0Awhich equals %d sqft.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %2
store i32 4, i32* %3
store i32 5, i32* %4
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8, i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = add nsw i32 %12, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %5
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %5
%24 = load i32, i32* %2
%25 = sub nsw i32 %23, %24
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = sub nsw i32 %26, %27
%29 = mul nsw i32 %25, %28
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = sub nsw i32 %30, %31
%33 = mul nsw i32 %29, %32
%34 = call i32 @sqrt(i32 %33)
store i32 %34, i32* %6
%35 = load i32, i32* %5
%36 = load i32, i32* %2
%37 = load i32, i32* %5
%38 = load i32, i32* %3
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36, i32 %37, i32 %38, i32 %39, i32 %40, i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [102 x i8] c"\0AUsing Heron's formula we are going to find the area of a\0Atriangle with the sides of %d, %d, and %d \0A\00"
@.str.2 = [48 x i8] c"Our triangle calcuates s=(%d+%d+%d)/2 so s=%d.\0A\00"
@.str.3 = [71 x i8] c"The area then is, sqrt((%d-%d)*(%d-%d)*(%d-%d) \0Awhich equals %d sqft.\0A\00"
@str = [73 x i8] c"Heron's formula is area = sqrt(s*(s-a)*(s-b)*(s-c)),\0Awhere s=(a+b+c)/2.\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i32 3, i32 4, i32 5)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 4, i32 5, i32 6)
%4 = tail call i32 @sqrt(i32 6)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i32 6, i32 3, i32 6, i32 4, i32 6, i32 5, i32 %4)
ret i32 0
}