#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, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isdigit(char);
char *malloc(int);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
float sqrt(scalar_t__);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int side1, side2, len, i;
  char *buffer = malloc(50);
  float hypot;
  if (buffer == NULL) {
    printf("Out of memory\n");
    return 1;
  }
  printf("Sida 1: ");
  fgets(buffer, 50, stdin);
  len = strlen(buffer) - 1;
  for (i = 0; i < len; ++i) {
    if (!isdigit(buffer[i])) {
      printf("Invalid input\n");
      return 1;
    }
  }
  side1 = atoi(buffer);
  printf("Sida 2: ");
  fgets(buffer, 50, stdin);
  len = strlen(buffer) - 1;
  for (i = 0; i < len; ++i) {
    if (!isdigit(buffer[i])) {
      printf("Invalid input\n");
      return 1;
    }
  }
  side2 = atoi(buffer);
  hypot = sqrt(pow(side1, 2) + pow(side2, 2));
  printf("Givet att sidorna är %d och %d\n", side1, side2);
  printf("så blir hypotenusan %f\n", hypot);
  free(buffer);
  buffer = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x32,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <main+0x42>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1e8>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1070 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1260 <main+0xd0>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    124d <main+0xbd>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1e8>
jmp    1252 <main+0xc2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120d <main+0x7d>
mov    -0x20(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x8(%rbp)
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1070 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12fa <main+0x16a>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    12e7 <main+0x157>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1378 <main+0x1e8>
jmp    12ec <main+0x15c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a7 <main+0x117>
mov    -0x20(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1090 <pow@plt>
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1090 <pow@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
call   10b0 <sqrt@plt>
movss  %xmm0,-0x24(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcf8(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x32,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12eb <main+0x14b>
mov    %rax,%r13
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e12(%rip),%r12
mov    (%r12),%edx
mov    %r13,%rdi
mov    $0x32,%esi
call   1080 <fgets@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     121c <main+0x7c>
mov    %eax,%ebp
add    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     12f4 <main+0x154>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0x60>
mov    %r13,%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
lea    0xddb(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%edx
mov    %r13,%rdi
mov    $0x32,%esi
call   1080 <fgets@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     127c <main+0xdc>
mov    %eax,%ebp
add    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   (%rax)
movsbl 0x0(%r13,%rbx,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     12f4 <main+0x154>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1260 <main+0xc0>
mov    %r13,%rdi
call   10b0 <atoi@plt>
mov    %eax,%r12d
mov    %r14d,%edi
mov    $0x2,%esi
call   10a0 <pow@plt>
mov    %rax,%rbp
mov    %r12d,%edi
mov    $0x2,%esi
call   10a0 <pow@plt>
add    %rax,%rbp
mov    %rbp,%rdi
call   10c0 <sqrt@plt>
movss  %xmm0,0x4(%rsp)
lea    0xd56(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd59(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    1306 <main+0x166>
lea    0xd68(%rip),%rdi
jmp    12fb <main+0x15b>
lea    0xd51(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [9 x i8] c"Sida 1: \00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"Invalid input\0A\00"
@.str.3 = [9 x i8] c"Sida 2: \00"
@.str.4 = [33 x i8] c"Givet att sidorna \C3\A4r %d och %d\0A\00"
@.str.5 = [25 x i8] c"s\C3\A5 blir hypotenusan %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca float
store i32 0, i32* %1
%8 = call i8* @malloc(i32 50)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%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 %84
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 50, i32 %16)
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %4
store i32 0, i32* %5
br label %21
21: ; preds = %36, %13
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @isdigit(i8 signext %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %25
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %84
35: ; preds = %25
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %21
39: ; preds = %21
%40 = load i8*, i8** %6
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %2
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8*, i8** %6
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %43, i32 50, i32 %44)
%46 = load i8*, i8** %6
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %47, 1
store i32 %48, i32* %4
store i32 0, i32* %5
br label %49
49: ; preds = %64, %39
%50 = load i32, i32* %5
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i8*, i8** %6
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = call i32 @isdigit(i8 signext %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %53
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %84
63: ; preds = %53
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %49
67: ; preds = %49
%68 = load i8*, i8** %6
%69 = call i32 @atoi(i8* %68)
store i32 %69, i32* %3
%70 = load i32, i32* %2
%71 = call i64 @pow(i32 %70, i32 2)
%72 = load i32, i32* %3
%73 = call i64 @pow(i32 %72, i32 2)
%74 = add nsw i64 %71, %73
%75 = call float @sqrt(i64 %74)
store float %75, float* %7
%76 = load i32, i32* %2
%77 = load i32, i32* %3
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %76, i32 %77)
%79 = load float, float* %7
%80 = fpext float %79 to double
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), double %80)
%82 = load i8*, i8** %6
%83 = call i32 @free(i8* %82)
store i8* null, i8** %6
store i32 0, i32* %1
br label %84
84: ; preds = %67, %61, %33, %11
%85 = load i32, i32* %1
ret i32 %85
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"Sida 1: \00"
@stdin = global i32 0
@.str.3 = [9 x i8] c"Sida 2: \00"
@.str.4 = [33 x i8] c"Givet att sidorna \C3\A4r %d och %d\0A\00"
@.str.5 = [25 x i8] c"s\C3\A5 blir hypotenusan %f\0A\00"
@str.6 = [14 x i8] c"Invalid input\00"
@str.7 = [14 x i8] c"Out of memory\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%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.7, i64 0, i64 0))
br label %56
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = tail call i32 @fgets(i8* %1, i32 50, i32 %7)
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %25
11: ; preds = %5
%12 = add nsw i32 %9, -1
%13 = zext i32 %12 to i64
br label %16
14: ; preds = %16
%15 = icmp eq i64 %22, %13
br i1 %15, label %25, label %16
16: ; preds = %11, %14
%17 = phi i64 [ 0, %11 ], [ %22, %14 ]
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @isdigit(i8 signext %19)
%21 = icmp eq i32 %20, 0
%22 = add nuw nsw i64 %17, 1
br i1 %21, label %23, label %14
23: ; preds = %16
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %56
25: ; preds = %14, %5
%26 = tail call i32 @atoi(i8* %1)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = tail call i32 @fgets(i8* %1, i32 50, i32 %28)
%30 = tail call i32 @strlen(i8* %1)
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %46
32: ; preds = %25
%33 = add nsw i32 %30, -1
%34 = zext i32 %33 to i64
br label %37
35: ; preds = %37
%36 = icmp eq i64 %43, %34
br i1 %36, label %46, label %37
37: ; preds = %32, %35
%38 = phi i64 [ 0, %32 ], [ %43, %35 ]
%39 = getelementptr inbounds i8, i8* %1, i64 %38
%40 = load i8, i8* %39
%41 = tail call i32 @isdigit(i8 signext %40)
%42 = icmp eq i32 %41, 0
%43 = add nuw nsw i64 %38, 1
br i1 %42, label %44, label %35
44: ; preds = %37
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %56
46: ; preds = %35, %25
%47 = tail call i32 @atoi(i8* %1)
%48 = tail call i64 @pow(i32 %26, i32 2)
%49 = tail call i64 @pow(i32 %47, i32 2)
%50 = add nsw i64 %49, %48
%51 = tail call float @sqrt(i64 %50)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %47)
%53 = fpext float %51 to double
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), double %53)
%55 = tail call i32 @free(i8* %1)
br label %56
56: ; preds = %46, %44, %23, %3
%57 = phi i32 [ 1, %3 ], [ 1, %23 ], [ 1, %44 ], [ 0, %46 ]
ret i32 %57
}