#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int const, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int const);
int /*<<< orphan*/ printf(char *, ...);
float sqrt(float);
int /*<<< orphan*/ stdin;
int main() {
  static const int maxdata = sizeof(int) * 2;
  char *inputholder = malloc(maxdata);
  if (inputholder == NULL) {
    printf("Out of memory\n");
    return 1;
  }
  int a, b, c;
  float s, area;
  printf(
      "Du kommer nu ombes att mata in längden för tre sidor av en triangel\n");
  printf("Sida 1: ");
  fgets(inputholder, maxdata, stdin);
  a = atoi(inputholder);
  printf("Sida 2: ");
  fgets(inputholder, maxdata, stdin);
  b = atoi(inputholder);
  printf("Sida 3: ");
  fgets(inputholder, maxdata, stdin);
  c = atoi(inputholder);
  if (a + b > c && a + c > b && b + c > a) {
    s = (a + b + c) / 2;
    area = sqrt(s * (s - a) * (s - b) * (s - c));
    printf("Arean är: %f", area);
  } else {
    printf("Sidorna kan inte utgöra en triangel\n");
    return 1;
  }
  free(inputholder);
  inputholder = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <main+0x42>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1bd>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    12eb <main+0x18b>
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    12eb <main+0x18b>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12eb <main+0x18b>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
cvtsi2ssl -0x14(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtsi2ssl -0x18(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtsi2ssl -0x1c(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
call   1080 <sqrt@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd96(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1305 <main+0x1a5>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1bd>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x8,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1282 <main+0x112>
mov    %rax,%rbx
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e39(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
lea    (%r15,%r14,1),%ecx
cmp    %eax,%ecx
jle    128b <main+0x11b>
lea    (%rax,%r14,1),%edx
cmp    %r15d,%edx
jle    128b <main+0x11b>
lea    (%rax,%r15,1),%edx
cmp    %r14d,%edx
jle    128b <main+0x11b>
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cvtsi2ss %edx,%xmm0
cvtsi2ss %r14d,%xmm1
movaps %xmm0,%xmm2
cvtsi2ss %r15d,%xmm3
subss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
movaps %xmm0,%xmm1
subss  %xmm3,%xmm1
mulss  %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
subss  %xmm2,%xmm0
mulss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     129e <main+0x12e>
sqrtss %xmm0,%xmm0
jmp    12a3 <main+0x133>
lea    0xe0b(%rip),%rdi
jmp    1292 <main+0x122>
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    12bf <main+0x14f>
call   1090 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
lea    0xd6d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.maxdata = internal constant i32 8
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [71 x i8] c"Du kommer nu ombes att mata in l\C3\A4ngden f\C3\B6r tre sidor av en triangel\0A\00"
@.str.2 = [9 x i8] c"Sida 1: \00"
@stdin = global i32 0
@.str.3 = [9 x i8] c"Sida 2: \00"
@.str.4 = [9 x i8] c"Sida 3: \00"
@.str.5 = [14 x i8] c"Arean \C3\A4r: %f\00"
@.str.6 = [38 x i8] c"Sidorna kan inte utg\C3\B6ra en triangel\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
%8 = call i8* @malloc(i32 8)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %83
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 8, i32 %17)
%19 = load i8*, i8** %2
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%22 = load i8*, i8** %2
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %22, i32 8, i32 %23)
%25 = load i8*, i8** %2
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%28 = load i8*, i8** %2
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %28, i32 8, i32 %29)
%31 = load i8*, i8** %2
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %5
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = add nsw i32 %33, %34
%36 = load i32, i32* %5
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %78
38: ; preds = %13
%39 = load i32, i32* %3
%40 = load i32, i32* %5
%41 = add nsw i32 %39, %40
%42 = load i32, i32* %4
%43 = icmp sgt i32 %41, %42
br i1 %43, label %44, label %78
44: ; preds = %38
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = add nsw i32 %45, %46
%48 = load i32, i32* %3
%49 = icmp sgt i32 %47, %48
br i1 %49, label %50, label %78
50: ; preds = %44
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = add nsw i32 %51, %52
%54 = load i32, i32* %5
%55 = add nsw i32 %53, %54
%56 = sdiv i32 %55, 2
%57 = sitofp i32 %56 to float
store float %57, float* %6
%58 = load float, float* %6
%59 = load float, float* %6
%60 = load i32, i32* %3
%61 = sitofp i32 %60 to float
%62 = fsub float %59, %61
%63 = fmul float %58, %62
%64 = load float, float* %6
%65 = load i32, i32* %4
%66 = sitofp i32 %65 to float
%67 = fsub float %64, %66
%68 = fmul float %63, %67
%69 = load float, float* %6
%70 = load i32, i32* %5
%71 = sitofp i32 %70 to float
%72 = fsub float %69, %71
%73 = fmul float %68, %72
%74 = call float @sqrt(float %73)
store float %74, float* %7
%75 = load float, float* %7
%76 = fpext float %75 to double
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %76)
br label %80
78: ; preds = %44, %38, %13
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %83
80: ; preds = %50
%81 = load i8*, i8** %2
%82 = call i32 @free(i8* %81)
store i8* null, i8** %2
store i32 0, i32* %1
br label %83
83: ; preds = %80, %78, %11
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"Sida 1: \00"
@stdin = global i32 0
@.str.3 = [9 x i8] c"Sida 2: \00"
@.str.4 = [9 x i8] c"Sida 3: \00"
@.str.5 = [14 x i8] c"Arean \C3\A4r: %f\00"
@str = [70 x i8] c"Du kommer nu ombes att mata in l\C3\A4ngden f\C3\B6r tre sidor av en triangel\00"
@str.7 = [37 x i8] c"Sidorna kan inte utg\C3\B6ra en triangel\00"
@str.8 = [14 x i8] c"Out of memory\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
br label %46
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgets(i8* %1, i32 8, i32 %8)
%10 = tail call i32 @atoi(i8* %1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = tail call i32 @fgets(i8* %1, i32 8, i32 %12)
%14 = tail call i32 @atoi(i8* %1)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = tail call i32 @fgets(i8* %1, i32 8, i32 %16)
%18 = tail call i32 @atoi(i8* %1)
%19 = add nsw i32 %14, %10
%20 = icmp sgt i32 %19, %18
%21 = add nsw i32 %18, %10
%22 = icmp sgt i32 %21, %14
%23 = select i1 %20, i1 %22, i1 false
%24 = add nsw i32 %18, %14
%25 = icmp sgt i32 %24, %10
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %27, label %44
27: ; preds = %5
%28 = add nsw i32 %18, %19
%29 = sdiv i32 %28, 2
%30 = sitofp i32 %29 to float
%31 = sitofp i32 %10 to float
%32 = fsub float %30, %31
%33 = fmul float %32, %30
%34 = sitofp i32 %14 to float
%35 = fsub float %30, %34
%36 = fmul float %35, %33
%37 = sitofp i32 %18 to float
%38 = fsub float %30, %37
%39 = fmul float %38, %36
%40 = tail call float @sqrt(float %39)
%41 = fpext float %40 to double
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %41)
%43 = tail call i32 @free(i8* %1)
br label %46
44: ; preds = %5
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %27, %3
%47 = phi i32 [ 1, %3 ], [ 0, %27 ], [ 1, %44 ]
ret i32 %47
}