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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
size_t rand();
void workBD(MYSQL_ROW row, int i) {
  int n[i];
  for (int p = 0; p <= i; p++) {
    n[p] = 0;
  }
  for (int p = 0; p <= i / 10; p++) {
    n[rand()] = 1;
  }
  FILE *file;
  FILE *file2;
  file = fopen("agrofinding.test", "w");
  file2 = fopen("agrofinding.train", "w");
  for (int p = 0; p <= i; p++) {
    if (n[p] == 0) {
      fwrite(row[p], sizeof(char *), 10, file);
      fwrite(" ", sizeof(char), 10, file);
    } else {
      fwrite(row[p], sizeof(char *), 10, file2);
      fwrite(" ", sizeof(char), 10, file2);
    }
  }
  fclose(file);
  fclose(file2);
}


x86 assembly (clang, -O0):
<workBD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11a6 <workBD+0x66>
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <workBD+0x3d>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jg     11ee <workBD+0xae>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <workBD+0x6d>
lea    0xe0b(%rip),%rdi
lea    0xe15(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe07(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12cb <workBD+0x18b>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    127f <workBD+0x13f>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x8,%esi
mov    $0xa,%edx
call   1050 <fwrite@plt>
mov    -0x30(%rbp),%rcx
lea    0xdba(%rip),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1050 <fwrite@plt>
jmp    12b8 <workBD+0x178>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x8,%esi
mov    $0xa,%edx
call   1050 <fwrite@plt>
mov    -0x38(%rbp),%rcx
lea    0xd7c(%rip),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1050 <fwrite@plt>
jmp    12bd <workBD+0x17d>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1223 <workBD+0xe3>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<workBD>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r13d
mov    %esi,%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
test   %esi,%esi
mov    %rdi,-0x40(%rbp)
js     1197 <workBD+0x47>
lea    0x4(,%rax,4),%rdx
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
jmp    119d <workBD+0x4d>
cmp    $0xfffffff7,%r13d
jb     11d4 <workBD+0x84>
movslq %r13d,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
sar    $0x22,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%ebx
add    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
movl   $0x1,(%r12,%rax,4)
add    $0xffffffff,%ebx
jne    11c0 <workBD+0x70>
lea    0xe25(%rip),%rdi
lea    0xe2f(%rip),%r14
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe1e(%rip),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
test   %r13d,%r13d
mov    -0x40(%rbp),%r15
js     126c <workBD+0x11c>
add    $0x1,%r13d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,(%r12,%r14,4)
mov    (%r15,%r14,8),%rdi
mov    %r13,%rbx
mov    -0x30(%rbp),%r13
cmove  -0x38(%rbp),%r13
mov    $0x8,%esi
mov    $0xa,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xdd7(%rip),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %r13,%rcx
mov    %rbx,%r13
call   1060 <fwrite@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1220 <workBD+0xd0>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"agrofinding.test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [18 x i8] c"agrofinding.train\00"
@.str.3 = [2 x i8] c" \00"
define void @workBD(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i32, i64 %13
store i64 %13, i64* %6
store i32 0, i32* %7
br label %16
16: ; preds = %24, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %15, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %16
27: ; preds = %16
store i32 0, i32* %8
br label %28
28: ; preds = %36, %27
%29 = load i32, i32* %8
%30 = load i32, i32* %4
%31 = sdiv i32 %30, 10
%32 = icmp sle i32 %29, %31
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = call i64 (...) @rand()
%35 = getelementptr inbounds i32, i32* %15, i64 %34
store i32 1, i32* %35
br label %36
36: ; preds = %33
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %28
39: ; preds = %28
%40 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %9
%41 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %10
store i32 0, i32* %11
br label %42
42: ; preds = %73, %39
%43 = load i32, i32* %11
%44 = load i32, i32* %4
%45 = icmp sle i32 %43, %44
br i1 %45, label %46, label %76
46: ; preds = %42
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %15, i64 %48
%50 = load i32, i32* %49
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %62
52: ; preds = %46
%53 = load i8**, i8*** %3
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = load i32*, i32** %9
%59 = call i32 @fwrite(i8* %57, i32 8, i32 10, i32* %58)
%60 = load i32*, i32** %9
%61 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 10, i32* %60)
br label %72
62: ; preds = %46
%63 = load i8**, i8*** %3
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
%68 = load i32*, i32** %10
%69 = call i32 @fwrite(i8* %67, i32 8, i32 10, i32* %68)
%70 = load i32*, i32** %10
%71 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 10, i32* %70)
br label %72
72: ; preds = %62, %52
br label %73
73: ; preds = %72
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %42
76: ; preds = %42
%77 = load i32*, i32** %9
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %10
%80 = call i32 @fclose(i32* %79)
%81 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"agrofinding.test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [18 x i8] c"agrofinding.train\00"
@.str.3 = [2 x i8] c" \00"
define void @workBD(i8** nocapture %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i32, i64 %3
%5 = icmp slt i32 %1, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = bitcast i32* %4 to i8*
%8 = shl nuw nsw i64 %3, 2
%9 = add nuw nsw i64 %8, 4
br label %12
10: ; preds = %2
%11 = icmp ult i32 %1, -9
br i1 %11, label %14, label %12
12: ; preds = %6, %10
%13 = sdiv i32 %1, 10
br label %20
14: ; preds = %20, %10
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br i1 %5, label %26, label %17
17: ; preds = %14
%18 = add nuw i32 %1, 1
%19 = zext i32 %18 to i64
br label %29
20: ; preds = %12, %20
%21 = phi i32 [ %24, %20 ], [ 0, %12 ]
%22 = tail call i64 (...) @rand()
%23 = getelementptr inbounds i32, i32* %4, i64 %22
store i32 1, i32* %23
%24 = add nuw nsw i32 %21, 1
%25 = icmp eq i32 %21, %13
br i1 %25, label %14, label %20
26: ; preds = %29, %14
%27 = tail call i32 @fclose(i32* %15)
%28 = tail call i32 @fclose(i32* %16)
ret void
29: ; preds = %17, %29
%30 = phi i64 [ 0, %17 ], [ %39, %29 ]
%31 = getelementptr inbounds i32, i32* %4, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
%34 = getelementptr inbounds i8*, i8** %0, i64 %30
%35 = load i8*, i8** %34
%36 = select i1 %33, i32* %15, i32* %16
%37 = tail call i32 @fwrite(i8* %35, i32 8, i32 10, i32* %36)
%38 = tail call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 10, i32* %36)
%39 = add nuw nsw i64 %30, 1
%40 = icmp eq i64 %39, %19
br i1 %40, label %26, label %29
}