#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 */
typedef int /*<<< orphan*/ numerator;
typedef int /*<<< orphan*/ denominator;

/* Variables and functions */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
float prevailingVisibility(char *visibility, int smNoUnits) {
  float Miles_vsby;
  char *temp, *Slash_ptr, *SM_KM_ptr, *end;
  char numerator[3], denominator[3];
  SM_KM_ptr = NULL;
  if ((SM_KM_ptr = strstr(visibility, "SM")) == NULL && !smNoUnits)
    SM_KM_ptr = strstr(visibility, "KM");
  Slash_ptr = strchr(visibility, '/');
  if (Slash_ptr == NULL) {
    temp = (char *)malloc(sizeof(char) * ((SM_KM_ptr - visibility) + 1));
    memset(temp, '\0', (SM_KM_ptr - visibility) + 1);
    strncpy(temp, visibility, (SM_KM_ptr - visibility));
    Miles_vsby = (float)(atoi(temp));
    free(temp);
    return Miles_vsby;
  } else {
    memset(numerator, '\0', sizeof(numerator));
    memset(denominator, '\0', sizeof(denominator));
    strncpy(numerator, visibility, (Slash_ptr - visibility));
    end = (SM_KM_ptr == NULL ? visibility + strlen(visibility) : SM_KM_ptr);
    strncpy(denominator, Slash_ptr + 1, (end - Slash_ptr));
    return (((float)(atoi(numerator))) / ((float)(atoi(denominator))));
  }
}


x86 assembly (clang, -O0):
<prevailingVisibility>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d3 <prevailingVisibility+0x53>
cmpl   $0x0,-0x14(%rbp)
jne    11d3 <prevailingVisibility+0x53>
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126f <prevailingVisibility+0xef>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1090 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1337 <prevailingVisibility+0x1b7>
lea    -0x3b(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1070 <memset@plt>
lea    -0x3e(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1070 <memset@plt>
lea    -0x3b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
cmpq   $0x0,-0x30(%rbp)
jne    12da <prevailingVisibility+0x15a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    12e2 <prevailingVisibility+0x162>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x3e(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    -0x3b(%rbp),%rdi
call   1090 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x54(%rbp)
lea    -0x3e(%rbp),%rdi
call   1090 <atoi@plt>
movss  -0x54(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prevailingVisibility>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe6a(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jne    11b9 <prevailingVisibility+0x39>
test   %rbx,%rbx
jne    11b9 <prevailingVisibility+0x39>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1268 <prevailingVisibility+0xe8>
mov    %rax,%r15
lea    0x15(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1070 <memset@plt>
lea    0x12(%rsp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1070 <memset@plt>
mov    %r15d,%edx
sub    %r14d,%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
test   %rbx,%rbx
jne    121b <prevailingVisibility+0x9b>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    %r15,%rsi
add    $0x1,%rsi
sub    %r15d,%ebx
lea    0x12(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1040 <strncpy@plt>
lea    0x15(%rsp),%rdi
call   1090 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbp,%rdi
call   1090 <atoi@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0xc(%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
jmp    12b5 <prevailingVisibility+0x135>
sub    %r14d,%ebx
lea    0x1(%rbx),%r15d
mov    %r15d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
mov    %rbp,%rdi
call   1090 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbp,%rdi
call   1030 <free@plt>
movss  0xc(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"SM\00"
@.str.1 = [3 x i8] c"KM\00"
define float @prevailingVisibility(i8* %0, i32 %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i32
%6 = alloca float
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [3 x i8]
%12 = alloca [3 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %9
%13 = load i8*, i8** %4
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %9
br label %22
22: ; preds = %19, %16, %2
%23 = load i8*, i8** %4
%24 = call i8* @strchr(i8* %23, i8 signext 47)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %62
27: ; preds = %22
%28 = load i8*, i8** %9
%29 = load i8*, i8** %4
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = add nsw i64 %32, 1
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = load i8*, i8** %9
%40 = load i8*, i8** %4
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = add nsw i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i32 @memset(i8* %38, i8 signext 0, i32 %45)
%47 = load i8*, i8** %7
%48 = load i8*, i8** %4
%49 = load i8*, i8** %9
%50 = load i8*, i8** %4
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i32
%55 = call i32 @strncpy(i8* %47, i8* %48, i32 %54)
%56 = load i8*, i8** %7
%57 = call i64 @atoi(i8* %56)
%58 = sitofp i64 %57 to float
store float %58, float* %6
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
%61 = load float, float* %6
store float %61, float* %3
br label %105
62: ; preds = %22
%63 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%64 = call i32 @memset(i8* %63, i8 signext 0, i32 3)
%65 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%66 = call i32 @memset(i8* %65, i8 signext 0, i32 3)
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%68 = load i8*, i8** %4
%69 = load i8*, i8** %8
%70 = load i8*, i8** %4
%71 = ptrtoint i8* %69 to i64
%72 = ptrtoint i8* %70 to i64
%73 = sub i64 %71, %72
%74 = trunc i64 %73 to i32
%75 = call i32 @strncpy(i8* %67, i8* %68, i32 %74)
%76 = load i8*, i8** %9
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %84
78: ; preds = %62
%79 = load i8*, i8** %4
%80 = load i8*, i8** %4
%81 = call i32 @strlen(i8* %80)
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
br label %86
84: ; preds = %62
%85 = load i8*, i8** %9
br label %86
86: ; preds = %84, %78
%87 = phi i8* [ %83, %78 ], [ %85, %84 ]
store i8* %87, i8** %10
%88 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%89 = load i8*, i8** %8
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = load i8*, i8** %10
%92 = load i8*, i8** %8
%93 = ptrtoint i8* %91 to i64
%94 = ptrtoint i8* %92 to i64
%95 = sub i64 %93, %94
%96 = trunc i64 %95 to i32
%97 = call i32 @strncpy(i8* %88, i8* %90, i32 %96)
%98 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%99 = call i64 @atoi(i8* %98)
%100 = sitofp i64 %99 to float
%101 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%102 = call i64 @atoi(i8* %101)
%103 = sitofp i64 %102 to float
%104 = fdiv float %100, %103
store float %104, float* %3
br label %105
105: ; preds = %86, %27
%106 = load float, float* %3
ret float %106
}

LLVM IR (-O2):
@.str = [3 x i8] c"SM\00"
@.str.1 = [3 x i8] c"KM\00"
define float @prevailingVisibility(i8* %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i8* %7, null
%9 = icmp ne i32 %1, 0
%10 = or i1 %9, %8
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = phi i8* [ %7, %2 ], [ %12, %11 ]
%15 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = ptrtoint i8* %14 to i64
%19 = ptrtoint i8* %0 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = add i32 %21, 1
%23 = tail call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @memset(i8* %24, i8 signext 0, i32 %22)
%26 = tail call i32 @strncpy(i8* %24, i8* %0, i32 %21)
%27 = tail call i64 @atoi(i8* %24)
%28 = sitofp i64 %27 to float
%29 = tail call i32 @free(i8* %24)
br label %55
30: ; preds = %13
%31 = call i32 @memset(i8* %5, i8 signext 0, i32 3)
%32 = call i32 @memset(i8* %6, i8 signext 0, i32 3)
%33 = ptrtoint i8* %15 to i64
%34 = ptrtoint i8* %0 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i32 @strncpy(i8* %5, i8* %0, i32 %36)
%38 = icmp eq i8* %14, null
br i1 %38, label %39, label %43
39: ; preds = %30
%40 = call i32 @strlen(i8* %0)
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
br label %43
43: ; preds = %30, %39
%44 = phi i8* [ %42, %39 ], [ %14, %30 ]
%45 = getelementptr inbounds i8, i8* %15, i64 1
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %46, %33
%48 = trunc i64 %47 to i32
%49 = call i32 @strncpy(i8* %6, i8* %45, i32 %48)
%50 = call i64 @atoi(i8* %5)
%51 = sitofp i64 %50 to float
%52 = call i64 @atoi(i8* %6)
%53 = sitofp i64 %52 to float
%54 = fdiv float %51, %53
br label %55
55: ; preds = %43, %17
%56 = phi float [ %28, %17 ], [ %54, %43 ]
ret float %56
}