#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 bufferLineToDouble(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char const *argv[]) {
  double *p = (double *)malloc(3 * sizeof(double));
  int i = 0;
  char *buffer = (char *)malloc(10 * sizeof(char));
  while (i < 3 && fgets(buffer, 12, stdin)) {
    double prob = bufferLineToDouble(buffer);
    if (prob < 0 || prob > 1.0) {
      printf("Given probability invalid\n");
      break;
    }
    p[i++] = prob;
  }
  double p0not1 = p[0] * (1 - p[1]);
  double p1not0 = p[1] * (1 - p[0]);
  double marginalP10 = p0not1 + p1not0;
  double prs = marginalP10 * p[2];
  printf("%lf\n", prs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x1c(%rbp)
mov    %al,-0x51(%rbp)
jge    11a9 <main+0x69>
mov    -0x28(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11b9 <main+0x79>
jmp    1220 <main+0xe0>
mov    -0x28(%rbp),%rdi
call   1050 <bufferLineToDouble@plt>
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
ja     11ec <main+0xac>
movsd  -0x30(%rbp),%xmm0
movsd  0xe1e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ff <main+0xbf>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <main+0xe0>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1179 <main+0x39>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0xdcc(%rip),%xmm1
subsd  0x8(%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0xda9(%rip),%xmm1
subsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xd91(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2e72(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0xc,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     122c <main+0xdc>
mov    %rbx,%rdi
call   1060 <bufferLineToDouble@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1220 <main+0xd0>
ucomisd 0xe57(%rip),%xmm0
ja     1220 <main+0xd0>
movsd  %xmm0,(%r14)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     122c <main+0xdc>
mov    %rbx,%rdi
call   1060 <bufferLineToDouble@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1220 <main+0xd0>
ucomisd 0xe21(%rip),%xmm0
ja     1220 <main+0xd0>
movsd  %xmm0,0x8(%r14)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     122c <main+0xdc>
mov    %rbx,%rdi
call   1060 <bufferLineToDouble@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1220 <main+0xd0>
ucomisd 0xdea(%rip),%xmm0
ja     1220 <main+0xd0>
movsd  %xmm0,0x10(%r14)
jmp    122c <main+0xdc>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
movupd (%r14),%xmm1
movapd 0xdd7(%rip),%xmm0
subpd  %xmm1,%xmm0
shufpd $0x1,%xmm1,%xmm1
mulpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0x10(%r14),%xmm0
lea    0xdc1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [27 x i8] c"Given probability invalid\0A\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i64 @malloc(i32 24)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %6
store i32 0, i32* %7
%16 = call i64 @malloc(i32 10)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %8
br label %18
18: ; preds = %38, %2
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i32, i32* @stdin
%24 = call i64 @fgets(i8* %22, i32 12, i32 %23)
%25 = icmp ne i64 %24, 0
br label %26
26: ; preds = %21, %18
%27 = phi i1 [ false, %18 ], [ %25, %21 ]
br i1 %27, label %28, label %45
28: ; preds = %26
%29 = load i8*, i8** %8
%30 = call double @bufferLineToDouble(i8* %29)
store double %30, double* %9
%31 = load double, double* %9
%32 = fcmp olt double %31, 0.000000e+00
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load double, double* %9
%35 = fcmp ogt double %34, 1.000000e+00
br i1 %35, label %36, label %38
36: ; preds = %33, %28
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %45
38: ; preds = %33
%39 = load double, double* %9
%40 = load double*, double** %6
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds double, double* %40, i64 %43
store double %39, double* %44
br label %18
45: ; preds = %36, %26
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 0
%48 = load double, double* %47
%49 = load double*, double** %6
%50 = getelementptr inbounds double, double* %49, i64 1
%51 = load double, double* %50
%52 = fsub double 1.000000e+00, %51
%53 = fmul double %48, %52
store double %53, double* %10
%54 = load double*, double** %6
%55 = getelementptr inbounds double, double* %54, i64 1
%56 = load double, double* %55
%57 = load double*, double** %6
%58 = getelementptr inbounds double, double* %57, i64 0
%59 = load double, double* %58
%60 = fsub double 1.000000e+00, %59
%61 = fmul double %56, %60
store double %61, double* %11
%62 = load double, double* %10
%63 = load double, double* %11
%64 = fadd double %62, %63
store double %64, double* %12
%65 = load double, double* %12
%66 = load double*, double** %6
%67 = getelementptr inbounds double, double* %66, i64 2
%68 = load double, double* %67
%69 = fmul double %65, %68
store double %69, double* %13
%70 = load double, double* %13
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %70)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [5 x i8] c"%lf\0A\00"
@str = [26 x i8] c"Given probability invalid\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 24)
%4 = inttoptr i64 %3 to double*
%5 = tail call i64 @malloc(i32 10)
%6 = inttoptr i64 %5 to i8*
%7 = load i32, i32* @stdin
%8 = tail call i64 @fgets(i8* %6, i32 12, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %38, label %10
10: ; preds = %2
%11 = tail call double @bufferLineToDouble(i8* %6)
%12 = fcmp olt double %11, 0.000000e+00
%13 = fcmp ogt double %11, 1.000000e+00
%14 = or i1 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %31, %21, %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %38
17: ; preds = %10
store double %11, double* %4
%18 = load i32, i32* @stdin
%19 = tail call i64 @fgets(i8* %6, i32 12, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %38, label %21
21: ; preds = %17
%22 = tail call double @bufferLineToDouble(i8* %6)
%23 = fcmp olt double %22, 0.000000e+00
%24 = fcmp ogt double %22, 1.000000e+00
%25 = or i1 %23, %24
br i1 %25, label %15, label %26
26: ; preds = %21
%27 = getelementptr inbounds double, double* %4, i64 1
store double %22, double* %27
%28 = load i32, i32* @stdin
%29 = tail call i64 @fgets(i8* %6, i32 12, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %26
%32 = tail call double @bufferLineToDouble(i8* %6)
%33 = fcmp olt double %32, 0.000000e+00
%34 = fcmp ogt double %32, 1.000000e+00
%35 = or i1 %33, %34
br i1 %35, label %15, label %36
36: ; preds = %31
%37 = getelementptr inbounds double, double* %4, i64 2
store double %32, double* %37
br label %38
38: ; preds = %2, %17, %26, %36, %15
%39 = inttoptr i64 %3 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%42 = fsub <2 x double> <double 1.000000e+00, double 1.000000e+00>, %40
%43 = fmul <2 x double> %41, %42
%44 = shufflevector <2 x double> %43, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%45 = fadd <2 x double> %43, %44
%46 = extractelement <2 x double> %45, i64 0
%47 = getelementptr inbounds double, double* %4, i64 2
%48 = load double, double* %47
%49 = fmul double %48, %46
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %49)
ret i32 0
}