#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, ...);
int write_mesh(char *fn, int nV, double *vertex, int nF, int *face,
               int *facematerial, int nT, int *tetra, int *tetramaterial) {
  int i;
  FILE *f;
  f = fopen(fn, "w");
  fprintf(f, "%5d\n", nV);
  for (i = 0; i < nV; i++) {
    fprintf(f, "%20.15lf %20.15lf %20.15lf\n", vertex[3 * i + 0],
            vertex[3 * i + 1], vertex[3 * i + 2]);
  }
  fprintf(f, "%5d\n", nT);
  for (i = 0; i < nT; i++) {
    fprintf(f, "%4d %4d %4d %4d  %d\n", tetra[4 * i + 0], tetra[4 * i + 1],
            tetra[4 * i + 2], tetra[4 * i + 3], tetramaterial[i]);
  }
  fprintf(f, "%5d\n", nF);
  for (i = 0; i < nF; i++) {
    fprintf(f, "%4d %4d %4d  %d\n", face[3 * i + 0], face[3 * i + 1],
            face[3 * i + 2], facematerial[i]);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<write_mesh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ee <write_mesh+0xbe>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%edx
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe2e(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1189 <write_mesh+0x59>
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1292 <write_mesh+0x162>
mov    -0x40(%rbp),%rdi
mov    0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x2,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    0x18(%rbp),%rax
mov    -0x34(%rbp),%esi
shl    $0x2,%esi
add    $0x2,%esi
movslq %esi,%rsi
mov    (%rax,%rsi,4),%r8d
mov    0x18(%rbp),%rax
mov    -0x34(%rbp),%esi
shl    $0x2,%esi
add    $0x3,%esi
movslq %esi,%rsi
mov    (%rax,%rsi,4),%r9d
mov    0x20(%rbp),%rax
movslq -0x34(%rbp),%rsi
mov    (%rax,%rsi,4),%eax
lea    0xda9(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120a <write_mesh+0xda>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131a <write_mesh+0x1ea>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
imul   $0x3,-0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x28(%rbp),%rax
imul   $0x3,-0x34(%rbp),%esi
add    $0x2,%esi
movslq %esi,%rsi
mov    (%rax,%rsi,4),%r8d
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rsi
mov    (%rax,%rsi,4),%r9d
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ae <write_mesh+0x17e>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_mesh>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbx
mov    %ecx,0xc(%rsp)
mov    %rdx,%r13
mov    %esi,%r12d
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r12d,%r12d
jle    11bb <write_mesh+0x8b>
mov    %r12d,%eax
shl    $0x3,%rax
lea    (%rax,%rax,2),%r14
xor    %ebp,%ebp
lea    0xe7b(%rip),%r12
nopl   0x0(%rax)
cvttsd2si 0x0(%r13,%rbp,1),%edx
movsd  0x8(%r13,%rbp,1),%xmm0
movsd  0x10(%r13,%rbp,1),%xmm1
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
add    $0x18,%rbp
cmp    %rbp,%r14
jne    1190 <write_mesh+0x60>
lea    0xe40(%rip),%rsi
mov    %r15,%rdi
mov    0x50(%rsp),%ebp
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
jle    1226 <write_mesh+0xf6>
mov    0x58(%rsp),%r13
mov    %ebp,%r14d
shl    $0x2,%r14
lea    0xe3a(%rip),%rbp
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    0x0(%r13,%r12,4),%edx
mov    0x4(%r13,%r12,4),%ecx
mov    0x8(%r13,%r12,4),%r8d
mov    0xc(%r13,%r12,4),%r9d
mov    0x60(%rsp),%rax
mov    (%rax,%r12,1),%eax
mov    %eax,(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x4,%r12
cmp    %r12,%r14
jne    11f0 <write_mesh+0xc0>
lea    0xdd5(%rip),%rsi
mov    %r15,%rdi
mov    0xc(%rsp),%ebp
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebp,%ebp
mov    0x10(%rsp),%r13
jle    1288 <write_mesh+0x158>
mov    %ebp,%r14d
add    $0x8,%rbx
lea    0xdd3(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    -0x8(%rbx),%edx
mov    -0x4(%rbx),%ecx
mov    (%rbx),%r8d
mov    0x0(%r13,%rbp,4),%r9d
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
add    $0xc,%rbx
cmp    %rbp,%r14
jne    1260 <write_mesh+0x130>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%5d\0A\00"
@.str.2 = [28 x i8] c"%20.15lf %20.15lf %20.15lf\0A\00"
@.str.3 = [21 x i8] c"%4d %4d %4d %4d %d\0A\00"
@.str.4 = [17 x i8] c"%4d %4d %4d %d\0A\00"
define i32 @write_mesh(i8* %0, i32 %1, double* %2, i32 %3, i32* %4, i32* %5, i32 %6, i32* %7, i32* %8) {
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32*
store i8* %0, i8** %10
store i32 %1, i32* %11
store double* %2, double** %12
store i32 %3, i32* %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32 %6, i32* %16
store i32* %7, i32** %17
store i32* %8, i32** %18
%21 = load i8*, i8** %10
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %20
%23 = load i32*, i32** %20
%24 = load i32, i32* %11
%25 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 0, i32* %19
br label %26
26: ; preds = %55, %9
%27 = load i32, i32* %19
%28 = load i32, i32* %11
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %58
30: ; preds = %26
%31 = load i32*, i32** %20
%32 = load double*, double** %12
%33 = load i32, i32* %19
%34 = mul nsw i32 3, %33
%35 = add nsw i32 %34, 0
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %32, i64 %36
%38 = load double, double* %37
%39 = fptosi double %38 to i32
%40 = load double*, double** %12
%41 = load i32, i32* %19
%42 = mul nsw i32 3, %41
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %40, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %12
%48 = load i32, i32* %19
%49 = mul nsw i32 3, %48
%50 = add nsw i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %47, i64 %51
%53 = load double, double* %52
%54 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %39, double %46, double %53)
br label %55
55: ; preds = %30
%56 = load i32, i32* %19
%57 = add nsw i32 %56, 1
store i32 %57, i32* %19
br label %26
58: ; preds = %26
%59 = load i32*, i32** %20
%60 = load i32, i32* %16
%61 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %60)
store i32 0, i32* %19
br label %62
62: ; preds = %102, %58
%63 = load i32, i32* %19
%64 = load i32, i32* %16
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %105
66: ; preds = %62
%67 = load i32*, i32** %20
%68 = load i32*, i32** %17
%69 = load i32, i32* %19
%70 = mul nsw i32 4, %69
%71 = add nsw i32 %70, 0
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %68, i64 %72
%74 = load i32, i32* %73
%75 = load i32*, i32** %17
%76 = load i32, i32* %19
%77 = mul nsw i32 4, %76
%78 = add nsw i32 %77, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %75, i64 %79
%81 = load i32, i32* %80
%82 = load i32*, i32** %17
%83 = load i32, i32* %19
%84 = mul nsw i32 4, %83
%85 = add nsw i32 %84, 2
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %82, i64 %86
%88 = load i32, i32* %87
%89 = load i32*, i32** %17
%90 = load i32, i32* %19
%91 = mul nsw i32 4, %90
%92 = add nsw i32 %91, 3
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %89, i64 %93
%95 = load i32, i32* %94
%96 = load i32*, i32** %18
%97 = load i32, i32* %19
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %96, i64 %98
%100 = load i32, i32* %99
%101 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %81, i32 %88, i32 %95, i32 %100)
br label %102
102: ; preds = %66
%103 = load i32, i32* %19
%104 = add nsw i32 %103, 1
store i32 %104, i32* %19
br label %62
105: ; preds = %62
%106 = load i32*, i32** %20
%107 = load i32, i32* %13
%108 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %106, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %107)
store i32 0, i32* %19
br label %109
109: ; preds = %142, %105
%110 = load i32, i32* %19
%111 = load i32, i32* %13
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %145
113: ; preds = %109
%114 = load i32*, i32** %20
%115 = load i32*, i32** %14
%116 = load i32, i32* %19
%117 = mul nsw i32 3, %116
%118 = add nsw i32 %117, 0
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i32, i32* %115, i64 %119
%121 = load i32, i32* %120
%122 = load i32*, i32** %14
%123 = load i32, i32* %19
%124 = mul nsw i32 3, %123
%125 = add nsw i32 %124, 1
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32, i32* %122, i64 %126
%128 = load i32, i32* %127
%129 = load i32*, i32** %14
%130 = load i32, i32* %19
%131 = mul nsw i32 3, %130
%132 = add nsw i32 %131, 2
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32, i32* %129, i64 %133
%135 = load i32, i32* %134
%136 = load i32*, i32** %15
%137 = load i32, i32* %19
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i32, i32* %136, i64 %138
%140 = load i32, i32* %139
%141 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %114, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %121, i32 %128, i32 %135, i32 %140)
br label %142
142: ; preds = %113
%143 = load i32, i32* %19
%144 = add nsw i32 %143, 1
store i32 %144, i32* %19
br label %109
145: ; preds = %109
%146 = load i32*, i32** %20
%147 = call i32 @fclose(i32* %146)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%5d\0A\00"
@.str.2 = [28 x i8] c"%20.15lf %20.15lf %20.15lf\0A\00"
@.str.3 = [21 x i8] c"%4d %4d %4d %4d %d\0A\00"
@.str.4 = [17 x i8] c"%4d %4d %4d %d\0A\00"
define i32 @write_mesh(i8* nocapture %0, i32 %1, double* nocapture %2, i32 %3, i32* nocapture %4, i32* nocapture %5, i32 %6, i32* nocapture %7, i32* nocapture %8) {
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %28, %15 ]
%17 = mul nuw nsw i64 %16, 3
%18 = getelementptr inbounds double, double* %2, i64 %17
%19 = load double, double* %18
%20 = fptosi double %19 to i32
%21 = add nuw nsw i64 %17, 1
%22 = getelementptr inbounds double, double* %2, i64 %21
%23 = load double, double* %22
%24 = add nuw nsw i64 %17, 2
%25 = getelementptr inbounds double, double* %2, i64 %24
%26 = load double, double* %25
%27 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %20, double %23, double %26)
%28 = add nuw nsw i64 %16, 1
%29 = icmp eq i64 %28, %14
br i1 %29, label %30, label %15
30: ; preds = %15, %9
%31 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%32 = icmp sgt i32 %6, 0
br i1 %32, label %33, label %54
33: ; preds = %30
%34 = zext i32 %6 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %52, %35 ]
%37 = shl nsw i64 %36, 2
%38 = getelementptr inbounds i32, i32* %7, i64 %37
%39 = load i32, i32* %38
%40 = or i64 %37, 1
%41 = getelementptr inbounds i32, i32* %7, i64 %40
%42 = load i32, i32* %41
%43 = or i64 %37, 2
%44 = getelementptr inbounds i32, i32* %7, i64 %43
%45 = load i32, i32* %44
%46 = or i64 %37, 3
%47 = getelementptr inbounds i32, i32* %7, i64 %46
%48 = load i32, i32* %47
%49 = getelementptr inbounds i32, i32* %8, i64 %36
%50 = load i32, i32* %49
%51 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %42, i32 %45, i32 %48, i32 %50)
%52 = add nuw nsw i64 %36, 1
%53 = icmp eq i64 %52, %34
br i1 %53, label %54, label %35
54: ; preds = %35, %30
%55 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%56 = icmp sgt i32 %3, 0
br i1 %56, label %57, label %75
57: ; preds = %54
%58 = zext i32 %3 to i64
br label %59
59: ; preds = %57, %59
%60 = phi i64 [ 0, %57 ], [ %73, %59 ]
%61 = mul nuw nsw i64 %60, 3
%62 = getelementptr inbounds i32, i32* %4, i64 %61
%63 = load i32, i32* %62
%64 = add nuw nsw i64 %61, 1
%65 = getelementptr inbounds i32, i32* %4, i64 %64
%66 = load i32, i32* %65
%67 = add nuw nsw i64 %61, 2
%68 = getelementptr inbounds i32, i32* %4, i64 %67
%69 = load i32, i32* %68
%70 = getelementptr inbounds i32, i32* %5, i64 %60
%71 = load i32, i32* %70
%72 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %63, i32 %66, i32 %69, i32 %71)
%73 = add nuw nsw i64 %60, 1
%74 = icmp eq i64 %73, %58
br i1 %74, label %75, label %59
75: ; preds = %59, %54
%76 = tail call i32 @fclose(i32* %10)
ret i32 0
}