#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 */
scalar_t__ atof(char *);
scalar_t__ isdigit(char);
double mean(char *, char *);
scalar_t__ pow(scalar_t__, int);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
char *strtok(char *, char *);
double variance(char *str, char *town) {
  char buff[strlen(str)];
  strcpy(buff, str);
  char line[200];
  double rain_mean = mean(str, town);
  char *pch = strtok(buff, "\n");
  while (pch != NULL) {
    if (strncmp(pch, town, strlen(town)) == 0) {
      strcpy(line, pch);
      break;
    }
    pch = strtok(NULL, "\n");
  }
  int cnt = 0;
  for (size_t i = 0; i < strlen(line); ++i) {
    if (isdigit(line[i]) || line[i] == '.' || line[i] == ',')
      line[cnt++] = line[i];
  }
  line[cnt] = '\0';
  double sum = 0;
  pch = strtok(line, ",");
  while (pch != NULL) {
    sum += pow(atof(pch) - rain_mean, 2);
    pch = strtok(NULL, ",");
  }
  return sum / 12;
}


x86 assembly (clang, -O0):
<variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    %rcx,%rax
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x120(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <mean@plt>
mov    -0x120(%rbp),%rdi
movsd  %xmm0,-0xf8(%rbp)
ff
lea    0xe17(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x100(%rbp)
cmpq   $0x0,-0x100(%rbp)
je     1281 <variance+0x101>
mov    -0x100(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1265 <variance+0xe5>
lea    -0xf0(%rbp),%rdi
mov    -0x100(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    1281 <variance+0x101>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd98(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x100(%rbp)
jmp    11fd <variance+0x7d>
movl   $0x0,-0x104(%rbp)
movq   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0xf0(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x138(%rbp),%rax
cmp    %rcx,%rax
jae    1355 <variance+0x1d5>
mov    -0x110(%rbp),%rax
movsbl -0xf0(%rbp,%rax,1),%edi
ff
call   1040 <isdigit@plt>
cmp    $0x0,%rax
jne    1311 <variance+0x191>
mov    -0x110(%rbp),%rax
movsbl -0xf0(%rbp,%rax,1),%eax
ff
cmp    $0x2e,%eax
je     1311 <variance+0x191>
mov    -0x110(%rbp),%rax
movsbl -0xf0(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
jne    1339 <variance+0x1b9>
mov    -0x110(%rbp),%rax
mov    -0xf0(%rbp,%rax,1),%cl
mov    -0x104(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x104(%rbp)
cltq
mov    %cl,-0xf0(%rbp,%rax,1)
jmp    133e <variance+0x1be>
mov    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x110(%rbp)
jmp    1296 <variance+0x116>
movslq -0x104(%rbp),%rax
movb   $0x0,-0xf0(%rbp,%rax,1)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x118(%rbp)
ff
lea    -0xf0(%rbp),%rdi
lea    0xc8d(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x100(%rbp)
cmpq   $0x0,-0x100(%rbp)
je     13f0 <variance+0x270>
mov    -0x100(%rbp),%rdi
call   1060 <atof@plt>
cvtsi2sd %rax,%xmm0
subsd  -0xf8(%rbp),%xmm0
ff
cvttsd2si %xmm0,%rdi
mov    $0x2,%esi
call   1080 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x118(%rbp),%xmm0
ff
movsd  %xmm0,-0x118(%rbp)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xc2b(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x100(%rbp)
jmp    1389 <variance+0x209>
movsd  -0x118(%rbp),%xmm0
ff
movsd  0xc00(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
call   1070 <strlen@plt>
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <mean@plt>
movsd  %xmm0,-0x28(%rbp)
lea    0xe3a(%rip),%r14
mov    %rbx,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1090 <strtok@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     120a <variance+0x8a>
xor    %edi,%edi
jmp    11e0 <variance+0x60>
lea    -0xf0(%rbp),%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    -0xf0(%rbp),%al
xor    %r15d,%r15d
test   %al,%al
je     1286 <variance+0x106>
mov    $0x1,%ebx
lea    -0xf0(%rbp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <isdigit@plt>
movzbl -0xf1(%rbp,%rbx,1),%ecx
ff
test   %rax,%rax
jne    125d <variance+0xdd>
mov    %ecx,%eax
or     $0x2,%al
cmp    $0x2e,%al
jne    126b <variance+0xeb>
movslq %r15d,%rax
add    $0x1,%r15d
mov    %cl,-0xf0(%rbp,%rax,1)
mov    %r14,%rdi
call   1070 <strlen@plt>
cmp    %rax,%rbx
jae    1286 <variance+0x106>
movzbl -0xf0(%rbp,%rbx,1),%eax
ff
add    $0x1,%rbx
jmp    1240 <variance+0xc0>
movslq %r15d,%rax
movb   $0x0,-0xf0(%rbp,%rax,1)
lea    0xd72(%rip),%rsi
lea    -0xf0(%rbp),%rdi
call   1090 <strtok@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     130b <variance+0x18b>
movsd  %xmm0,-0x20(%rbp)
lea    0xd51(%rip),%rbx
nopl   0x0(%rax)
mov    %rax,%rdi
call   1060 <atof@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%rdi
mov    $0x2,%esi
call   1080 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x20(%rbp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
jne    12c0 <variance+0x140>
jmp    1310 <variance+0x190>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  0xce3(%rip),%xmm0
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c",\00"
define double @variance(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [200 x i8]
%8 = alloca double
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
%12 = alloca double
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call double @mean(i8* %19, i8* %20)
store double %21, double* %8
%22 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %9
br label %23
23: ; preds = %37, %2
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i8*, i8** %9
%28 = load i8*, i8** %4
%29 = load i8*, i8** %4
%30 = call i64 @strlen(i8* %29)
%31 = call i64 @strncmp(i8* %27, i8* %28, i64 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%35 = load i8*, i8** %9
%36 = call i32 @strcpy(i8* %34, i8* %35)
br label %39
37: ; preds = %26
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %38, i8** %9
br label %23
39: ; preds = %33, %23
store i32 0, i32* %10
store i64 0, i64* %11
br label %40
40: ; preds = %72, %39
%41 = load i64, i64* %11
%42 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = icmp ult i64 %41, %43
br i1 %44, label %45, label %75
45: ; preds = %40
%46 = load i64, i64* %11
%47 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call i64 @isdigit(i8 signext %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %63, label %51
51: ; preds = %45
%52 = load i64, i64* %11
%53 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 46
br i1 %56, label %63, label %57
57: ; preds = %51
%58 = load i64, i64* %11
%59 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 44
br i1 %62, label %63, label %71
63: ; preds = %57, %51, %45
%64 = load i64, i64* %11
%65 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %69
store i8 %66, i8* %70
br label %71
71: ; preds = %63, %57
br label %72
72: ; preds = %71
%73 = load i64, i64* %11
%74 = add i64 %73, 1
store i64 %74, i64* %11
br label %40
75: ; preds = %40
%76 = load i32, i32* %10
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 %77
store i8 0, i8* %78
store double 0.000000e+00, double* %12
%79 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%80 = call i8* @strtok(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %80, i8** %9
br label %81
81: ; preds = %84, %75
%82 = load i8*, i8** %9
%83 = icmp ne i8* %82, null
br i1 %83, label %84, label %96
84: ; preds = %81
%85 = load i8*, i8** %9
%86 = call i64 @atof(i8* %85)
%87 = sitofp i64 %86 to double
%88 = load double, double* %8
%89 = fsub double %87, %88
%90 = fptosi double %89 to i64
%91 = call i64 @pow(i64 %90, i32 2)
%92 = sitofp i64 %91 to double
%93 = load double, double* %12
%94 = fadd double %93, %92
store double %94, double* %12
%95 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %95, i8** %9
br label %81
96: ; preds = %81
%97 = load double, double* %12
%98 = fdiv double %97, 1.200000e+01
%99 = load i8*, i8** %5
ret double %98
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c",\00"
define double @variance(i8* %0, i8* %1) {
%3 = alloca [200 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = alloca i8, i64 %4
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%8 = call double @mean(i8* %0, i8* %1)
%9 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %16, %2
%11 = phi i8* [ %17, %16 ], [ %9, %2 ]
%12 = icmp ne i8* %11, null
%13 = call i64 @strlen(i8* dereferenceable(1) %1)
%14 = call i64 @strncmp(i8* %11, i8* %1, i64 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %10
18: ; preds = %10
%19 = call i32 @strcpy(i8* %7, i8* %11)
%20 = load i8, i8* %7
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %41, %18
%23 = phi i32 [ 0, %18 ], [ %42, %41 ]
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %61, label %49
28: ; preds = %18, %46
%29 = phi i8 [ %48, %46 ], [ %20, %18 ]
%30 = phi i64 [ %43, %46 ], [ 0, %18 ]
%31 = phi i32 [ %42, %46 ], [ 0, %18 ]
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %30
%33 = call i64 @isdigit(i8 signext %29)
%34 = icmp eq i64 %33, 0
%35 = load i8, i8* %32
br i1 %34, label %36, label %37
36: ; preds = %28
switch i8 %35, label %41 [
i8 46, label %37
i8 44, label %37
]
37: ; preds = %28, %36, %36
%38 = add nsw i32 %31, 1
%39 = sext i32 %31 to i64
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %39
store i8 %35, i8* %40
br label %41
41: ; preds = %36, %37
%42 = phi i32 [ %38, %37 ], [ %31, %36 ]
%43 = add nuw i64 %30, 1
%44 = call i64 @strlen(i8* %7)
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %22
46: ; preds = %41
%47 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %43
%48 = load i8, i8* %47
br label %28
49: ; preds = %22, %49
%50 = phi double [ %58, %49 ], [ 0.000000e+00, %22 ]
%51 = phi i8* [ %59, %49 ], [ %26, %22 ]
%52 = call i64 @atof(i8* %51)
%53 = sitofp i64 %52 to double
%54 = fsub double %53, %8
%55 = fptosi double %54 to i64
%56 = call i64 @pow(i64 %55, i32 2)
%57 = sitofp i64 %56 to double
%58 = fadd double %50, %57
%59 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %49
61: ; preds = %49, %22
%62 = phi double [ 0.000000e+00, %22 ], [ %58, %49 ]
%63 = fdiv double %62, 1.200000e+01
ret double %63
}