#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ RAND_MAX;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ getpid();
char *malloc(scalar_t__);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int main(int argc, char *argv[]) {
  char line[80];
  FILE *ifp, *ofp;
  int points, i, count;
  srand((unsigned int)getpid());
  if (argc != 2) {
    fprintf(stderr, "specify an input file\n");
    return 1;
  }
  ifp = fopen(argv[1], "r");
  if (fgets(line, sizeof(line), ifp) == NULL) {
    fprintf(stderr, "failed to read the input file\n");
    return 1;
  }
  fclose(ifp);
  points = atoi(line);
  count = 0;
  for (i = 0; i < points; i++) {
    float x = (float)rand() / ((float)RAND_MAX + 1.0F);
    float y = (float)rand() / ((float)RAND_MAX + 1.0F);
    if (x * x + y * y < 1.0) {
      count += 1;
    }
  }
  char *ofilename = malloc(strlen(argv[1]) + 5);
  strncpy(ofilename, argv[1], strlen(argv[1]) + 1);
  strncat(ofilename, ".out", 4);
  ofp = fopen(ofilename, "w");
  fprintf(ofp, "%d/%d\n", count, points);
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1080 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
je     1215 <main+0x55>
mov    0x2de0(%rip),%rax
movslq (%rax),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x248>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdff(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    126d <main+0xad>
mov    0x2d88(%rip),%rax
movslq (%rax),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x248>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x60(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    134d <main+0x18d>
mov    $0x0,%al
call   10e0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2d39(%rip),%rax
cvtsi2ssq (%rax),%xmm1
movss  0xd4c(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x80(%rbp)
mov    $0x0,%al
call   10e0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2d0c(%rip),%rax
cvtsi2ssq (%rax),%xmm1
movss  0xd1f(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
movss  -0x80(%rbp),%xmm0
movss  -0x80(%rbp),%xmm2
movss  -0x84(%rbp),%xmm1
ff
mulss  -0x84(%rbp),%xmm1
ff
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcd9(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    133a <main+0x17a>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    133f <main+0x17f>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1290 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x5,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x90(%rbp),%rdi
lea    0xc85(%rip),%rsi
mov    $0x4,%edx
call   1070 <strncat@plt>
mov    -0x90(%rbp),%rdi
lea    0xc72(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x7c(%rbp),%edx
mov    -0x74(%rbp),%ecx
lea    0xc5a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
call   1080 <srand@plt>
cmp    $0x2,%ebx
jne    134a <main+0x17a>
mov    0x8(%r14),%rdi
lea    0xe16(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1362 <main+0x192>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x10(%rsp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
xor    %r12d,%r12d
mov    $0x0,%ebp
test   %eax,%eax
jle    12d7 <main+0x107>
mov    0x2d94(%rip),%r13
mov    %r15d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   10f0 <rand@plt>
xorps  %xmm2,%xmm2
cvtsi2ss %rax,%xmm2
xorps  %xmm0,%xmm0
cvtsi2ssq 0x0(%r13),%xmm0
movss  0xd80(%rip),%xmm1
addss  %xmm1,%xmm0
divss  %xmm0,%xmm2
movss  %xmm2,0xc(%rsp)
xor    %eax,%eax
call   10f0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq 0x0(%r13),%xmm1
movss  0xd52(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
mulss  %xmm0,%xmm0
movss  0xc(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
xor    %eax,%eax
ucomiss %xmm1,%xmm2
seta   %al
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1260 <main+0x90>
mov    0x8(%r14),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
lea    0x5(%rax),%rdi
call   10b0 <malloc@plt>
mov    %rax,%r13
add    $0x1,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
lea    0xd31(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1070 <strncat@plt>
lea    0xd22(%rip),%rsi
mov    %r13,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xd12(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1388 <main+0x1b8>
mov    0x2c87(%rip),%rax
movslq (%rax),%rcx
lea    0xca9(%rip),%rdi
mov    $0x16,%esi
jmp    1378 <main+0x1a8>
mov    0x2c6f(%rip),%rax
movslq (%rax),%rcx
lea    0xcaa(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"specify an input file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"failed to read the input file\0A\00"
@RAND_MAX = global i64 0
@.str.3 = [5 x i8] c".out\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [7 x i8] c"%d/%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca float
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i64 (...) @getpid()
%16 = trunc i64 %15 to i32
%17 = call i32 @srand(i32 %16)
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %103
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %7
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %7
%32 = call i32* @fgets(i8* %30, i32 80, i32* %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %103
39: ; preds = %25
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %9
store i32 0, i32* %11
store i32 0, i32* %10
br label %44
44: ; preds = %73, %39
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %76
48: ; preds = %44
%49 = call i64 (...) @rand()
%50 = sitofp i64 %49 to float
%51 = load i64, i64* @RAND_MAX
%52 = sitofp i64 %51 to float
%53 = fadd float %52, 1.000000e+00
%54 = fdiv float %50, %53
store float %54, float* %12
%55 = call i64 (...) @rand()
%56 = sitofp i64 %55 to float
%57 = load i64, i64* @RAND_MAX
%58 = sitofp i64 %57 to float
%59 = fadd float %58, 1.000000e+00
%60 = fdiv float %56, %59
store float %60, float* %13
%61 = load float, float* %12
%62 = load float, float* %12
%63 = load float, float* %13
%64 = load float, float* %13
%65 = fmul float %63, %64
%66 = call float @llvm.fmuladd.f32(float %61, float %62, float %65)
%67 = fpext float %66 to double
%68 = fcmp olt double %67, 1.000000e+00
br i1 %68, label %69, label %72
69: ; preds = %48
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
br label %72
72: ; preds = %69, %48
br label %73
73: ; preds = %72
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
store i32 %75, i32* %10
br label %44
76: ; preds = %44
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i64 @strlen(i8* %79)
%81 = add nsw i64 %80, 5
%82 = call i8* @malloc(i64 %81)
store i8* %82, i8** %14
%83 = load i8*, i8** %14
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i64 @strlen(i8* %89)
%91 = add nsw i64 %90, 1
%92 = call i32 @strncpy(i8* %83, i8* %86, i64 %91)
%93 = load i8*, i8** %14
%94 = call i32 @strncat(i8* %93, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%95 = load i8*, i8** %14
%96 = call i32* @fopen(i8* %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %96, i32** %8
%97 = load i32*, i32** %8
%98 = load i32, i32* %11
%99 = load i32, i32* %9
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %97, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %98, i32 %99)
%101 = load i32*, i32** %8
%102 = call i32 @fclose(i32* %101)
store i32 0, i32* %3
br label %103
103: ; preds = %76, %34, %20
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"specify an input file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"failed to read the input file\0A\00"
@RAND_MAX = global i64 0
@.str.3 = [5 x i8] c".out\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [7 x i8] c"%d/%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i64 (...) @getpid()
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 22, i64 1, i32* %12)
br label %63
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32* @fgets(i8* %4, i32 80, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 30, i64 1, i32* %23)
br label %63
25: ; preds = %14
%26 = call i32 @fclose(i32* %17)
%27 = call i32 @atoi(i8* %4)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %51
29: ; preds = %25, %29
%30 = phi i32 [ %49, %29 ], [ 0, %25 ]
%31 = phi i32 [ %48, %29 ], [ 0, %25 ]
%32 = call i64 (...) @rand()
%33 = sitofp i64 %32 to float
%34 = load i64, i64* @RAND_MAX
%35 = sitofp i64 %34 to float
%36 = fadd float %35, 1.000000e+00
%37 = fdiv float %33, %36
%38 = call i64 (...) @rand()
%39 = sitofp i64 %38 to float
%40 = load i64, i64* @RAND_MAX
%41 = sitofp i64 %40 to float
%42 = fadd float %41, 1.000000e+00
%43 = fdiv float %39, %42
%44 = fmul float %43, %43
%45 = call float @llvm.fmuladd.f32(float %37, float %37, float %44)
%46 = fcmp olt float %45, 1.000000e+00
%47 = zext i1 %46 to i32
%48 = add nuw nsw i32 %31, %47
%49 = add nuw nsw i32 %30, 1
%50 = icmp eq i32 %49, %27
br i1 %50, label %51, label %29
51: ; preds = %29, %25
%52 = phi i32 [ 0, %25 ], [ %48, %29 ]
%53 = load i8*, i8** %15
%54 = call i64 @strlen(i8* dereferenceable(1) %53)
%55 = add nsw i64 %54, 5
%56 = call i8* @malloc(i64 %55)
%57 = add nsw i64 %54, 1
%58 = call i32 @strncpy(i8* %56, i8* %53, i64 %57)
%59 = call i32 @strncat(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%60 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %52, i32 %27)
%62 = call i32 @fclose(i32* %60)
br label %63
63: ; preds = %51, %20, %9
%64 = phi i32 [ 1, %9 ], [ 1, %20 ], [ 0, %51 ]
ret i32 %64
}