#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, ...);
int /*<<< orphan*/ libaft_3d_warn(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int write_front(char *fn, int nV, double *vertex, int nF, int *face,
                int *facematerial) {
  int i;
  FILE *f;
  f = fopen(fn, "w");
  if (!f) {
    libaft_3d_warn("write_front: %s: %s", fn, strerror(errno));
    return 1;
  }
  fprintf(f, "%d %d\n", nV, nF);
  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]);
  for (i = 0; i < nF; i++)
    fprintf(f, "%d %d %d %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_front>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11c1 <write_front+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xe52(%rip),%rdi
call   1050 <libaft_3d_warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <write_front+0x178>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1245 <write_front+0xf5>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%edx
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%ecx
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%esi
add    $0x2,%esi
movslq %esi,%rsi
movsd  (%rax,%rsi,8),%xmm0
lea    0xde6(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e0 <write_front+0x90>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12b8 <write_front+0x168>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x30(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%esi
add    $0x2,%esi
movslq %esi,%rsi
mov    (%rax,%rsi,4),%r8d
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r9d
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    124c <write_front+0xfc>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_front>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %esi,%r13d
mov    %rdi,%r12
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1243 <write_front+0xf3>
mov    %rax,%r15
lea    0xea7(%rip),%rsi
mov    %rax,%rdi
mov    %r13d,%edx
mov    %r14d,0xc(%rsp)
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r13d,%r13d
jle    11eb <write_front+0x9b>
mov    %r13d,%eax
shl    $0x3,%rax
lea    (%rax,%rax,2),%r12
xor    %r14d,%r14d
lea    0xe56(%rip),%r13
cvttsd2si 0x0(%rbp,%r14,1),%edx
cvttsd2si 0x8(%rbp,%r14,1),%ecx
movsd  0x10(%rbp,%r14,1),%xmm0
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x18,%r14
cmp    %r14,%r12
jne    11c0 <write_front+0x70>
mov    0xc(%rsp),%eax
test   %eax,%eax
mov    0x10(%rsp),%r14
jle    1237 <write_front+0xe7>
mov    %eax,%r13d
add    $0x8,%rbx
lea    0xe2c(%rip),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rbx),%edx
mov    -0x4(%rbx),%ecx
mov    (%rbx),%r8d
mov    (%r14,%rbp,4),%r9d
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
add    $0xc,%rbx
cmp    %rbp,%r13
jne    1210 <write_front+0xc0>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1267 <write_front+0x117>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdaa(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <libaft_3d_warn@plt>
mov    $0x1,%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 = [20 x i8] c"write_front: %s: %s\00"
@errno = global i32 0
@.str.2 = [7 x i8] c"%d %d\0A\00"
@.str.3 = [28 x i8] c"%20.15lf %20.15lf %20.15lf\0A\00"
@.str.4 = [13 x i8] c"%d %d %d %d\0A\00"
define i32 @write_front(i8* %0, i32 %1, double* %2, i32 %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32*
store i8* %0, i8** %8
store i32 %1, i32* %9
store double* %2, double** %10
store i32 %3, i32* %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%16 = load i8*, i8** %8
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %15
%18 = load i32*, i32** %15
%19 = icmp ne i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %6
%21 = load i8*, i8** %8
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @libaft_3d_warn(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %23)
store i32 1, i32* %7
br label %103
25: ; preds = %6
%26 = load i32*, i32** %15
%27 = load i32, i32* %9
%28 = load i32, i32* %11
%29 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
store i32 0, i32* %14
br label %30
30: ; preds = %60, %25
%31 = load i32, i32* %14
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %63
34: ; preds = %30
%35 = load i32*, i32** %15
%36 = load double*, double** %10
%37 = load i32, i32* %14
%38 = mul nsw i32 3, %37
%39 = add nsw i32 %38, 0
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %36, i64 %40
%42 = load double, double* %41
%43 = fptosi double %42 to i32
%44 = load double*, double** %10
%45 = load i32, i32* %14
%46 = mul nsw i32 3, %45
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %44, i64 %48
%50 = load double, double* %49
%51 = fptosi double %50 to i32
%52 = load double*, double** %10
%53 = load i32, i32* %14
%54 = mul nsw i32 3, %53
%55 = add nsw i32 %54, 2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %52, i64 %56
%58 = load double, double* %57
%59 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %51, double %58)
br label %60
60: ; preds = %34
%61 = load i32, i32* %14
%62 = add nsw i32 %61, 1
store i32 %62, i32* %14
br label %30
63: ; preds = %30
store i32 0, i32* %14
br label %64
64: ; preds = %97, %63
%65 = load i32, i32* %14
%66 = load i32, i32* %11
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %100
68: ; preds = %64
%69 = load i32*, i32** %15
%70 = load i32*, i32** %12
%71 = load i32, i32* %14
%72 = mul nsw i32 3, %71
%73 = add nsw i32 %72, 0
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %70, i64 %74
%76 = load i32, i32* %75
%77 = load i32*, i32** %12
%78 = load i32, i32* %14
%79 = mul nsw i32 3, %78
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %77, i64 %81
%83 = load i32, i32* %82
%84 = load i32*, i32** %12
%85 = load i32, i32* %14
%86 = mul nsw i32 3, %85
%87 = add nsw i32 %86, 2
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %84, i64 %88
%90 = load i32, i32* %89
%91 = load i32*, i32** %13
%92 = load i32, i32* %14
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
%96 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %76, i32 %83, i32 %90, i32 %95)
br label %97
97: ; preds = %68
%98 = load i32, i32* %14
%99 = add nsw i32 %98, 1
store i32 %99, i32* %14
br label %64
100: ; preds = %64
%101 = load i32*, i32** %15
%102 = call i32 @fclose(i32* %101)
store i32 0, i32* %7
br label %103
103: ; preds = %100, %20
%104 = load i32, i32* %7
ret i32 %104
}

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