#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 *);
char *strchr(char const *, char);
double tr2v(const char *op) {
  char *pt;
  int num, denom;
  pt = strchr(op, '/');
  if (!pt)
    return 0.;
  denom = atoi(pt + 1);
  for (; pt != op && *pt != '+' && *pt != '-'; pt--)
    ;
  num = atoi(pt);
  return (double)num / (double)denom;
}


x86 assembly (clang, -O0):
<tr2v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <tr2v+0x36>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e3 <tr2v+0xc3>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     119e <tr2v+0x7e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2b,%ecx
mov    %al,-0x21(%rbp)
je     119e <tr2v+0x7e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ae <tr2v+0x8e>
jmp    11c4 <tr2v+0xa4>
jmp    11b3 <tr2v+0x93>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <tr2v+0x46>
mov    -0x18(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tr2v>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117d <tr2v+0x5d>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebp
cmp    %r14,%rbx
je     1164 <tr2v+0x44>
nopl   0x0(%rax)
movzbl (%rbx),%eax
cmp    $0x2b,%al
je     1167 <tr2v+0x47>
cmp    $0x2d,%al
je     1167 <tr2v+0x47>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jne    1150 <tr2v+0x30>
mov    %r14,%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
cvtsi2sd %eax,%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
jmp    1181 <tr2v+0x61>
xorpd  %xmm0,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @tr2v(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store double 0.000000e+00, double* %2
br label %44
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %33, %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = icmp ne i8* %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 43
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 45
br label %30
30: ; preds = %25, %20, %16
%31 = phi i1 [ false, %20 ], [ false, %16 ], [ %29, %25 ]
br i1 %31, label %32, label %36
32: ; preds = %30
br label %33
33: ; preds = %32
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %4
br label %16
36: ; preds = %30
%37 = load i8*, i8** %4
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = sitofp i32 %39 to double
%41 = load i32, i32* %6
%42 = sitofp i32 %41 to double
%43 = fdiv double %40, %42
store double %43, double* %2
br label %44
44: ; preds = %36, %11
%45 = load double, double* %2
ret double %45
}

LLVM IR (-O2):
define double @tr2v(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = ptrtoint i8* %3 to i64
%5 = icmp eq i8* %3, null
br i1 %5, label %25, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp eq i8* %3, %0
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = sub i64 %2, %4
%12 = getelementptr i8, i8* %3, i64 %11
br label %13
13: ; preds = %10, %16
%14 = phi i8* [ %17, %16 ], [ %3, %10 ]
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 43, label %19
i8 45, label %19
]
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 -1
%18 = icmp eq i8* %17, %0
br i1 %18, label %19, label %13
19: ; preds = %16, %13, %13, %6
%20 = phi i8* [ %0, %6 ], [ %14, %13 ], [ %14, %13 ], [ %12, %16 ]
%21 = tail call i32 @atoi(i8* %20)
%22 = sitofp i32 %21 to double
%23 = sitofp i32 %8 to double
%24 = fdiv double %22, %23
br label %25
25: ; preds = %1, %19
%26 = phi double [ %24, %19 ], [ 0.000000e+00, %1 ]
ret double %26
}