#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 cents2interv(double);
int sscanf(char *, char *, double *, double *);
int /*<<< orphan*/ *strchr(char *, char);
double str2ratio(char *s) {
  double n, d;
  int c;
  if ((c = sscanf(s, "%lf/%lf\n", &n, &d)) > 0) {
    if (c == 1 && strchr(s, '.') != NULL)
      return cents2interv(n);
    else if (d != 0.0)
      return (n / d);
  }
  return 0.0;
}


x86 assembly (clang, -O0):
<str2ratio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    11d1 <str2ratio+0xa1>
cmpl   $0x1,-0x24(%rbp)
jne    1196 <str2ratio+0x66>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1196 <str2ratio+0x66>
movsd  -0x18(%rbp),%xmm0
call   1040 <cents2interv@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <str2ratio+0xa9>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b3 <str2ratio+0x83>
jp     11b3 <str2ratio+0x83>
jmp    11c7 <str2ratio+0x97>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <str2ratio+0xa9>
jmp    11cc <str2ratio+0x9c>
jmp    11d1 <str2ratio+0xa1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2ratio>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xec1(%rip),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
call   1050 <sscanf@plt>
test   %eax,%eax
jle    1190 <str2ratio+0x60>
cmp    $0x1,%eax
jne    1173 <str2ratio+0x43>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1173 <str2ratio+0x43>
movsd  (%rsp),%xmm0
call   1040 <cents2interv@plt>
jmp    1194 <str2ratio+0x64>
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1185 <str2ratio+0x55>
jnp    1194 <str2ratio+0x64>
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
jmp    1194 <str2ratio+0x64>
xorpd  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%lf/%lf\0A\00"
define double @str2ratio(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double* %4, double* %5)
store i32 %8, i32* %6
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i32* @strchr(i8* %14, i8 signext 46)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load double, double* %4
%19 = call double @cents2interv(double %18)
store double %19, double* %2
br label %30
20: ; preds = %13, %10
%21 = load double, double* %5
%22 = fcmp une double %21, 0.000000e+00
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fdiv double %24, %25
store double %26, double* %2
br label %30
27: ; preds = %20
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28, %1
store double 0.000000e+00, double* %2
br label %30
30: ; preds = %29, %23, %17
%31 = load double, double* %2
ret double %31
}

LLVM IR (-O2):
@.str = [9 x i8] c"%lf/%lf\0A\00"
define double @str2ratio(i8* %0) {
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %2 to i8*
%5 = bitcast double* %3 to i8*
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double* %2, double* %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = icmp eq i32 %6, 1
br i1 %9, label %10, label %16
10: ; preds = %8
%11 = call i32* @strchr(i8* %0, i8 signext 46)
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load double, double* %2
%15 = call double @cents2interv(double %14)
br label %22
16: ; preds = %10, %8
%17 = load double, double* %3
%18 = fcmp une double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %2
%21 = fdiv double %20, %17
br label %22
22: ; preds = %1, %16, %19, %13
%23 = phi double [ %15, %13 ], [ %21, %19 ], [ 0.000000e+00, %16 ], [ 0.000000e+00, %1 ]
ret double %23
}