#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) {
  FILE *fptr;
  int i, j;
  char outFileName[1024];
  sprintf(outFileName, "%s.cluster_centres", filename);
  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);
  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    %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    0xe7e(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0xc(%rbp),%esi
lea    -0x440(%rbp),%rdx
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1248 <file_write+0xf8>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1228 <file_write+0xd8>
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    0xe40(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e3 <file_write+0x93>
mov    -0x30(%rbp),%rdi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bb <file_write+0x6b>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x440(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%esi
lea    -0x440(%rbp),%rdx
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12d6 <file_write+0x186>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    129c <file_write+0x14c>
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),%rbx
mov    %rbx,%rdi
mov    %rdx,0x8(%rsp)
call   1080 <sprintf@plt>
lea    0xe6d(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1247 <file_write+0xe7>
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
mov    (%rsp),%r13d
lea    0xe78(%rip),%r15
xor    %r12d,%r12d
jmp    11f8 <file_write+0x98>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     1247 <file_write+0xe7>
mov    %rbx,%rdi
lea    0xe4d(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
cmpl   $0x0,(%rsp)
jle    11e0 <file_write+0x80>
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    1220 <file_write+0xc0>
jmp    11e0 <file_write+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe01(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
call   1080 <sprintf@plt>
lea    0xdf6(%rip),%rdi
mov    0x4(%rsp),%ebp
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
lea    0xdc9(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %ebp,%ebp
mov    0x10(%rsp),%r12
jle    12cc <file_write+0x16c>
mov    %ebp,%ebx
lea    0xdfa(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    12b0 <file_write+0x150>
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) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float**
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [1024 x i8]
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store float** %4, float*** %11
store i32* %5, i32** %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %8
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %13
store i32 0, i32* %14
br label %25
25: ; preds = %56, %6
%26 = load i32, i32* %14
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %59
29: ; preds = %25
%30 = load i32*, i32** %13
%31 = load i32, i32* %14
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
store i32 0, i32* %15
br label %33
33: ; preds = %50, %29
%34 = load i32, i32* %15
%35 = load i32, i32* %10
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %53
37: ; preds = %33
%38 = load i32*, i32** %13
%39 = load float**, float*** %11
%40 = load i32, i32* %14
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float*, float** %39, i64 %41
%43 = load float*, float** %42
%44 = load i32, i32* %15
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %43, i64 %45
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %48)
br label %50
50: ; preds = %37
%51 = load i32, i32* %15
%52 = add nsw i32 %51, 1
store i32 %52, i32* %15
br label %33
53: ; preds = %33
%54 = load i32*, i32** %13
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %53
%57 = load i32, i32* %14
%58 = add nsw i32 %57, 1
store i32 %58, i32* %14
br label %25
59: ; preds = %25
%60 = load i32*, i32** %13
%61 = call i32 @fclose(i32* %60)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%63 = load i8*, i8** %7
%64 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %9
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%67 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i32 %65, i8* %66)
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%69 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %69, i32** %13
store i32 0, i32* %14
br label %70
70: ; preds = %83, %59
%71 = load i32, i32* %14
%72 = load i32, i32* %9
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %86
74: ; preds = %70
%75 = load i32*, i32** %13
%76 = load i32, i32* %14
%77 = load i32*, i32** %12
%78 = load i32, i32* %14
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
%81 = load i32, i32* %80
%82 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %76, i32 %81)
br label %83
83: ; preds = %74
%84 = load i32, i32* %14
%85 = add nsw i32 %84, 1
store i32 %85, i32* %14
br label %70
86: ; preds = %70
%87 = load i32*, i32** %13
%88 = call i32 @fclose(i32* %87)
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) {
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %8)
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %36
13: ; preds = %6
%14 = icmp sgt i32 %3, 0
%15 = zext i32 %1 to i64
%16 = zext i32 %3 to i64
br label %17
17: ; preds = %13, %32
%18 = phi i64 [ 0, %13 ], [ %34, %32 ]
%19 = trunc i64 %18 to i32
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br i1 %14, label %21, label %32
21: ; preds = %17
%22 = getelementptr inbounds float*, float** %4, i64 %18
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %30, %23 ]
%25 = load float*, float** %22
%26 = getelementptr inbounds float, float* %25, i64 %24
%27 = load float, float* %26
%28 = fpext float %27 to double
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %28)
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %16
br i1 %31, label %32, label %23
32: ; preds = %23, %17
%33 = call i32 @fputc(i32 10, i32* %11)
%34 = add nuw nsw i64 %18, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %17
36: ; preds = %32, %6
%37 = call i32 @fclose(i32* %11)
%38 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%39 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0), i32 %2, i8* %8)
%40 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp sgt i32 %2, 0
br i1 %41, label %42, label %52
42: ; preds = %36
%43 = zext i32 %2 to i64
br label %44
44: ; preds = %42, %44
%45 = phi i64 [ 0, %42 ], [ %50, %44 ]
%46 = getelementptr inbounds i32, i32* %5, i64 %45
%47 = load i32, i32* %46
%48 = trunc i64 %45 to i32
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %48, i32 %47)
%50 = add nuw nsw i64 %45, 1
%51 = icmp eq i64 %50, %43
br i1 %51, label %52, label %44
52: ; preds = %44, %36
%53 = call i32 @fclose(i32* %40)
ret i32 1
}