#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*/ FILE;

/* Variables and functions */
float atof(char *);
float drand48();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
float *load_mock_file(char *, int *);
int /*<<< orphan*/ srand48(float);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  float frac;
  FILE *in;
  FILE *out;
  float *x, *y, *z;
  int n_points;
  int i;
  float tmp;
  if (argc != 6) {
    fprintf(stderr, "USAGE: %s\n",
            "./sub_sample.x filein_x filein_y filein_z fileout frac\n");
    exit(1);
  }
  x = load_mock_file(argv[1], &n_points);
  y = load_mock_file(argv[2], &n_points);
  z = load_mock_file(argv[3], &n_points);
  frac = atof(argv[5]);
  srand48(frac * 1000);
  if (!(out = fopen(argv[4], "w"))) {
    fprintf(stderr, "Problem opening file %s\n", argv[4]);
    exit(1);
  }
  for (i = 0; i < n_points; i++) {
    tmp = drand48();
    if (tmp < frac) {
      fprintf(out, "%e %e %e\n", x[i], y[i], z[i]);
    }
  }
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     11c9 <main+0x49>
mov    0x2e39(%rip),%rax
movslq (%rax),%rdi
lea    0xe53(%rip),%rsi
lea    0xe57(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x44(%rbp),%rsi
call   1050 <load_mock_file@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x44(%rbp),%rsi
call   1050 <load_mock_file@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x44(%rbp),%rsi
call   1050 <load_mock_file@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x14(%rbp)
movss  0xdde(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
call   1070 <srand48@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe0c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1278 <main+0xf8>
mov    0x2d8b(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1302 <main+0x182>
mov    $0x0,%al
call   10a0 <drand48@plt>
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    12ef <main+0x16f>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd7a(%rip),%rsi
mov    $0x3,%al
call   1060 <fprintf@plt>
jmp    12f4 <main+0x174>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    127f <main+0xff>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x6,%edi
jne    1285 <main+0x105>
mov    %rsi,%r13
mov    0x8(%rsi),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <load_mock_file@plt>
mov    %rax,%r14
mov    0x10(%r13),%rdi
mov    %rbx,%rsi
call   1050 <load_mock_file@plt>
mov    %rax,%r15
mov    0x18(%r13),%rdi
mov    %rbx,%rsi
call   1050 <load_mock_file@plt>
mov    %rax,%r12
mov    0x28(%r13),%rdi
call   1030 <atof@plt>
movaps %xmm0,%xmm1
movss  0xe25(%rip),%xmm0
movss  %xmm1,0x4(%rsp)
mulss  %xmm1,%xmm0
call   1070 <srand48@plt>
mov    0x20(%r13),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     129f <main+0x11f>
mov    %rax,%rbx
cmpl   $0x0,(%rsp)
jle    126c <main+0xec>
lea    0xe4f(%rip),%r13
xor    %ebp,%ebp
jmp    122d <main+0xad>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jge    126c <main+0xec>
xor    %eax,%eax
call   10a0 <drand48@plt>
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1220 <main+0xa0>
movss  (%r14,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%r15,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
movss  (%r12,%rbp,4),%xmm2
cvtss2sd %xmm2,%xmm2
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x3,%al
call   1060 <fprintf@plt>
jmp    1220 <main+0xa0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d54(%rip),%rax
movslq (%rax),%rdi
lea    0xd6e(%rip),%rsi
lea    0xd72(%rip),%rdx
jmp    12b4 <main+0x134>
mov    0x2d3a(%rip),%rax
movslq (%rax),%rdi
mov    0x20(%r13),%rdx
lea    0xd95(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"USAGE: %s\0A\00"
@.str.1 = [56 x i8] c"./sub_sample.x filein_x filein_y filein_z fileout frac\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [25 x i8] c"Problem opening file %s\0A\00"
@.str.4 = [10 x i8] c"%e %e %e\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call float* @load_mock_file(i8* %26, i32* %12)
store float* %27, float** %9
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call float* @load_mock_file(i8* %30, i32* %12)
store float* %31, float** %10
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call float* @load_mock_file(i8* %34, i32* %12)
store float* %35, float** %11
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
%39 = call float @atof(i8* %38)
store float %39, float* %6
%40 = load float, float* %6
%41 = fmul float %40, 1.000000e+03
%42 = call i32 @srand48(float %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %8
%47 = icmp ne i32* %46, null
br i1 %47, label %57, label %48
48: ; preds = %23
%49 = load i32, i32* @stderr
%50 = sext i32 %49 to i64
%51 = inttoptr i64 %50 to i32*
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 4
%54 = load i8*, i8** %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %23
store i32 0, i32* %13
br label %58
58: ; preds = %89, %57
%59 = load i32, i32* %13
%60 = load i32, i32* %12
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %92
62: ; preds = %58
%63 = call float (...) @drand48()
store float %63, float* %14
%64 = load float, float* %14
%65 = load float, float* %6
%66 = fcmp olt float %64, %65
br i1 %66, label %67, label %88
67: ; preds = %62
%68 = load i32*, i32** %8
%69 = load float*, float** %9
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds float, float* %69, i64 %71
%73 = load float, float* %72
%74 = fpext float %73 to double
%75 = load float*, float** %10
%76 = load i32, i32* %13
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds float, float* %75, i64 %77
%79 = load float, float* %78
%80 = fpext float %79 to double
%81 = load float*, float** %11
%82 = load i32, i32* %13
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds float, float* %81, i64 %83
%85 = load float, float* %84
%86 = fpext float %85 to double
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %74, double %80, double %86)
br label %88
88: ; preds = %67, %62
br label %89
89: ; preds = %88
%90 = load i32, i32* %13
%91 = add nsw i32 %90, 1
store i32 %91, i32* %13
br label %58
92: ; preds = %58
%93 = load i32*, i32** %8
%94 = call i32 @fclose(i32* %93)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"USAGE: %s\0A\00"
@.str.1 = [56 x i8] c"./sub_sample.x filein_x filein_y filein_z fileout frac\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [25 x i8] c"Problem opening file %s\0A\00"
@.str.4 = [10 x i8] c"%e %e %e\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 6
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call float* @load_mock_file(i8* %14, i32* %3)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call float* @load_mock_file(i8* %17, i32* %3)
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = call float* @load_mock_file(i8* %20, i32* %3)
%22 = getelementptr inbounds i8*, i8** %1, i64 5
%23 = load i8*, i8** %22
%24 = call float @atof(i8* %23)
%25 = fmul float %24, 1.000000e+03
%26 = call i32 @srand48(float %25)
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %12
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 0
br i1 %33, label %41, label %61
34: ; preds = %12
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = load i8*, i8** %27
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %31, %56
%42 = phi i64 [ %57, %56 ], [ 0, %31 ]
%43 = call float (...) @drand48()
%44 = fcmp olt float %43, %24
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = getelementptr inbounds float, float* %15, i64 %42
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = getelementptr inbounds float, float* %18, i64 %42
%50 = load float, float* %49
%51 = fpext float %50 to double
%52 = getelementptr inbounds float, float* %21, i64 %42
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %48, double %51, double %54)
br label %56
56: ; preds = %41, %45
%57 = add nuw nsw i64 %42, 1
%58 = load i32, i32* %3
%59 = sext i32 %58 to i64
%60 = icmp slt i64 %57, %59
br i1 %60, label %41, label %61
61: ; preds = %56, %31
%62 = call i32 @fclose(i32* %29)
ret i32 0
}