#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int file_write(char *filename, int numClusters, int numObjs, int numCoords,
               float **clusters, int *membership, int verbose) {
  FILE *fptr;
  int i, j;
  char outFileName[1024];
  sprintf(outFileName, "%s.cluster_centres", filename);
  if (verbose)
    printf("Writing coordinates of K=%d cluster centers to file \"%s\"\n",
           numClusters, outFileName);
  fptr = fopen(outFileName, "w");
  for (i = 0; i < numClusters; i++) {
    fprintf(fptr, "%d ", i);
    for (j = 0; j < numCoords; j++)
      fprintf(fptr, "%f ", clusters[i][j]);
    fprintf(fptr, "\n");
  }
  fclose(fptr);
  sprintf(outFileName, "%s.membership", filename);
  if (verbose)
    printf("Writing membership of N=%d data objects to file \"%s\"\n", numObjs,
           outFileName);
  fptr = fopen(outFileName, "w");
  for (i = 0; i < numObjs; i++)
    fprintf(fptr, "%d %d\n", i, membership[i]);
  fclose(fptr);
  return 1;
}


x86 assembly (clang, -O0):
<file_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1070 <sprintf@plt>
cmpl   $0x0,0x10(%rbp)
je     11aa <file_write+0x5a>
mov    -0xc(%rbp),%esi
lea    -0x440(%rbp),%rdx
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1255 <file_write+0x105>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1235 <file_write+0xe5>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe33(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11f0 <file_write+0xa0>
mov    -0x30(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c8 <file_write+0x78>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x440(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xde7(%rip),%rsi
call   1070 <sprintf@plt>
cmpl   $0x0,0x10(%rbp)
je     1295 <file_write+0x145>
mov    -0x10(%rbp),%esi
lea    -0x440(%rbp),%rdx
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12ed <file_write+0x19d>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12b3 <file_write+0x163>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbp
mov    %ecx,(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%r14d
mov    %rdi,%rdx
lea    0xe73(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %rdx,0x8(%rsp)
call   1080 <sprintf@plt>
cmpl   $0x0,0x460(%rsp)
je     11ba <file_write+0x5a>
lea    0xe66(%rip),%rdi
lea    0x20(%rsp),%rdx
mov    %r14d,%esi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1257 <file_write+0xf7>
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
mov    (%rsp),%r13d
lea    0xe69(%rip),%r15
xor    %r12d,%r12d
jmp    1208 <file_write+0xa8>
nop
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     1257 <file_write+0xf7>
mov    %rbx,%rdi
lea    0xe3d(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
cmpl   $0x0,(%rsp)
jle    11f0 <file_write+0x90>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%rbp,%r12,8),%rax
movss  (%rax,%r14,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1230 <file_write+0xd0>
jmp    11f0 <file_write+0x90>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xdf1(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    0x8(%rsp),%rdx
call   1080 <sprintf@plt>
cmpl   $0x0,0x460(%rsp)
mov    0x4(%rsp),%ebx
je     1296 <file_write+0x136>
lea    0xddb(%rip),%rdi
lea    0x20(%rsp),%rdx
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0xdb0(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %ebx,%ebx
mov    0x10(%rsp),%r12
jle    12dc <file_write+0x17c>
mov    %ebx,%ebx
lea    0xddf(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r12,%rbp,4),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12c0 <file_write+0x160>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%s.cluster_centres\00"
@.str.1 = [58 x i8] c"Writing coordinates of K=%d cluster centers to file \22%s\22\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [4 x i8] c"%f \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [14 x i8] c"%s.membership\00"
@.str.7 = [54 x i8] c"Writing membership of N=%d data objects to file \22%s\22\0A\00"
@.str.8 = [7 x i8] c"%d %d\0A\00"
define i32 @file_write(i8* %0, i32 %1, i32 %2, i32 %3, float** %4, i32* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float**
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca [1024 x i8]
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store float** %4, float*** %12
store i32* %5, i32** %13
store i32 %6, i32* %14
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %14
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %7
%25 = load i32, i32* %9
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26)
br label %28
28: ; preds = %24, %7
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %15
store i32 0, i32* %16
br label %31
31: ; preds = %62, %28
%32 = load i32, i32* %16
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %65
35: ; preds = %31
%36 = load i32*, i32** %15
%37 = load i32, i32* %16
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %37)
store i32 0, i32* %17
br label %39
39: ; preds = %56, %35
%40 = load i32, i32* %17
%41 = load i32, i32* %11
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %59
43: ; preds = %39
%44 = load i32*, i32** %15
%45 = load float**, float*** %12
%46 = load i32, i32* %16
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float*, float** %45, i64 %47
%49 = load float*, float** %48
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float, float* %49, i64 %51
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %54)
br label %56
56: ; preds = %43
%57 = load i32, i32* %17
%58 = add nsw i32 %57, 1
store i32 %58, i32* %17
br label %39
59: ; preds = %39
%60 = load i32*, i32** %15
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %59
%63 = load i32, i32* %16
%64 = add nsw i32 %63, 1
store i32 %64, i32* %16
br label %31
65: ; preds = %31
%66 = load i32*, i32** %15
%67 = call i32 @fclose(i32* %66)
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%69 = load i8*, i8** %8
%70 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %14
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %65
%74 = load i32, i32* %10
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%76 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i32 %74, i8* %75)
br label %77
77: ; preds = %73, %65
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %79, i32** %15
store i32 0, i32* %16
br label %80
80: ; preds = %93, %77
%81 = load i32, i32* %16
%82 = load i32, i32* %10
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %96
84: ; preds = %80
%85 = load i32*, i32** %15
%86 = load i32, i32* %16
%87 = load i32*, i32** %13
%88 = load i32, i32* %16
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32, i32* %90
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %86, i32 %91)
br label %93
93: ; preds = %84
%94 = load i32, i32* %16
%95 = add nsw i32 %94, 1
store i32 %95, i32* %16
br label %80
96: ; preds = %80
%97 = load i32*, i32** %15
%98 = call i32 @fclose(i32* %97)
ret i32 1
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s.cluster_centres\00"
@.str.1 = [58 x i8] c"Writing coordinates of K=%d cluster centers to file \22%s\22\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [4 x i8] c"%f \00"
@.str.6 = [14 x i8] c"%s.membership\00"
@.str.7 = [54 x i8] c"Writing membership of N=%d data objects to file \22%s\22\0A\00"
@.str.8 = [7 x i8] c"%d %d\0A\00"
define i32 @file_write(i8* %0, i32 %1, i32 %2, i32 %3, float** nocapture %4, i32* nocapture %5, i32 %6) {
%8 = alloca [1024 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = icmp eq i32 %6, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %9)
br label %14
14: ; preds = %12, %7
%15 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %40
17: ; preds = %14
%18 = icmp sgt i32 %3, 0
%19 = zext i32 %1 to i64
%20 = zext i32 %3 to i64
br label %21
21: ; preds = %17, %36
%22 = phi i64 [ 0, %17 ], [ %38, %36 ]
%23 = trunc i64 %22 to i32
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br i1 %18, label %25, label %36
25: ; preds = %21
%26 = getelementptr inbounds float*, float** %4, i64 %22
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %34, %27 ]
%29 = load float*, float** %26
%30 = getelementptr inbounds float, float* %29, i64 %28
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %32)
%34 = add nuw nsw i64 %28, 1
%35 = icmp eq i64 %34, %20
br i1 %35, label %36, label %27
36: ; preds = %27, %21
%37 = call i32 @fputc(i32 10, i32* %15)
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, %19
br i1 %39, label %40, label %21
40: ; preds = %36, %14
%41 = call i32 @fclose(i32* %15)
%42 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br i1 %11, label %45, label %43
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i32 %2, i8* %9)
br label %45
45: ; preds = %43, %40
%46 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = icmp sgt i32 %2, 0
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = zext i32 %2 to i64
br label %50
50: ; preds = %48, %50
%51 = phi i64 [ 0, %48 ], [ %56, %50 ]
%52 = getelementptr inbounds i32, i32* %5, i64 %51
%53 = load i32, i32* %52
%54 = trunc i64 %51 to i32
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %54, i32 %53)
%56 = add nuw nsw i64 %51, 1
%57 = icmp eq i64 %56, %49
br i1 %57, label %58, label %50
58: ; preds = %50, %45
%59 = call i32 @fclose(i32* %46)
ret i32 1
}