#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
int snprintf(char *, int, char *, int, ...);
int /*<<< orphan*/ stderr;
void obj_write(const char *file_name, int component_count, int point_count,
               float *points) {
  FILE *fp = fopen(file_name, "wb");
  if (!fp) {
    perror(file_name);
    exit(EXIT_FAILURE);
  }
  for (int row = 0; row < point_count; row++) {
    fwrite("v ", 2, 1, fp);
    for (int col = 0; col < component_count; col++) {
      float coord = points[row * component_count + col];
      char coord_string[100];
      int len = snprintf(coord_string, 100, "%.6f ", coord);
      if (fwrite(coord_string, len, 1, fp) != 1) {
        fclose(fp);
        fputs("ERR: write capture data: failed to write file.", stderr);
        exit(EXIT_FAILURE);
      }
    }
    fwrite("\n", 1, 1, fp);
  }
  for (int row = 0; row < point_count; row += 3) {
    char face_string[100];
    int len =
        snprintf(face_string, 100, "f %d %d %d\n", row + 1, row + 2, row + 3);
    if (fwrite(face_string, len, 1, fp) != 1) {
      fclose(fp);
      fputs("ERR: write capture data: failed to write file.", stderr);
      exit(EXIT_FAILURE);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<obj_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bf <obj_write+0x4f>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12c7 <obj_write+0x157>
mov    -0x20(%rbp),%rcx
lea    0xe26(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a2 <obj_write+0x132>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x2c(%rbp)
lea    -0x90(%rbp),%rdi
cvttss2si -0x2c(%rbp),%ecx
mov    $0x64,%esi
lea    0xdd4(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     128f <obj_write+0x11f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    0xd90(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1294 <obj_write+0x124>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f3 <obj_write+0x83>
mov    -0x20(%rbp),%rcx
lea    0xd98(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <obj_write+0x56>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1388 <obj_write+0x218>
lea    -0x100(%rbp),%rdi
mov    -0x98(%rbp),%ecx
add    $0x1,%ecx
mov    -0x98(%rbp),%r8d
add    $0x2,%r8d
mov    -0x98(%rbp),%r9d
add    $0x3,%r9d
mov    $0x64,%esi
lea    0xd29(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x104(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x104(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     136f <obj_write+0x1ff>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
lea    0xcb0(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1374 <obj_write+0x204>
mov    -0x98(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x98(%rbp)
jmp    12d1 <obj_write+0x161>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obj_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %esi,(%rsp)
mov    %rdi,%r14
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1325 <obj_write+0x1a5>
mov    %rax,%rbx
test   %r15d,%r15d
jle    12e0 <obj_write+0x160>
movslq (%rsp),%rax
mov    %r15d,0x4(%rsp)
mov    %r15d,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r15d
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
lea    0xe24(%rip),%r13
lea    0x20(%rsp),%r14
xor    %eax,%eax
jmp    1212 <obj_write+0x92>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    0x18(%rsp),%rax
add    $0x1,%rax
add    0x10(%rsp),%rbp
cmp    0x8(%rsp),%rax
je     1282 <obj_write+0x102>
mov    %rax,0x18(%rsp)
lea    0xde5(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
cmpl   $0x0,(%rsp)
jle    11f0 <obj_write+0x70>
xor    %r12d,%r12d
nopl   0x0(%rax)
cvttss2si 0x0(%rbp,%r12,4),%ecx
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
jne    12fa <obj_write+0x17a>
add    $0x1,%r12
cmp    %r12,%r15
jne    1240 <obj_write+0xc0>
jmp    11f0 <obj_write+0x70>
mov    0x4(%rsp),%r12d
test   %r12d,%r12d
jle    12e0 <obj_write+0x160>
lea    0xda8(%rip),%r14
lea    0x20(%rsp),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r8d
lea    0x1(%r8),%ecx
lea    0x3(%r8),%ebp
add    $0x2,%r8d
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%r9d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
jne    12fa <obj_write+0x17a>
cmp    %r12d,%ebp
jl     12a0 <obj_write+0x120>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
lea    0xcfa(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r14,%rdi
call   1080 <perror@plt>
jmp    1317 <obj_write+0x197>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"v \00"
@.str.2 = [6 x i8] c"%.6f \00"
@.str.3 = [47 x i8] c"ERR: write capture data: failed to write file.\00"
@stderr = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [12 x i8] c"f %d %d %d\0A\00"
define void @obj_write(i8* %0, i32 %1, i32 %2, float* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca [100 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca [100 x i8]
%17 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store float* %3, float** %8
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp ne i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %4
%23 = load i8*, i8** %5
%24 = call i32 @perror(i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %4
store i32 0, i32* %10
br label %28
28: ; preds = %72, %27
%29 = load i32, i32* %10
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %75
32: ; preds = %28
%33 = load i32*, i32** %9
%34 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %33)
store i32 0, i32* %11
br label %35
35: ; preds = %66, %32
%36 = load i32, i32* %11
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %69
39: ; preds = %35
%40 = load float*, float** %8
%41 = load i32, i32* %10
%42 = load i32, i32* %6
%43 = mul nsw i32 %41, %42
%44 = load i32, i32* %11
%45 = add nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds float, float* %40, i64 %46
%48 = load float, float* %47
store float %48, float* %12
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%50 = load float, float* %12
%51 = fptosi float %50 to i32
%52 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %49, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 %52, i32* %14
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%54 = load i32, i32* %14
%55 = load i32*, i32** %9
%56 = call i32 @fwrite(i8* %53, i32 %54, i32 1, i32* %55)
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %65
58: ; preds = %39
%59 = load i32*, i32** %9
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* @stderr
%62 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %39
br label %66
66: ; preds = %65
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %35
69: ; preds = %35
%70 = load i32*, i32** %9
%71 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 1, i32* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %28
75: ; preds = %28
store i32 0, i32* %15
br label %76
76: ; preds = %102, %75
%77 = load i32, i32* %15
%78 = load i32, i32* %7
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %105
80: ; preds = %76
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%82 = load i32, i32* %15
%83 = add nsw i32 %82, 1
%84 = load i32, i32* %15
%85 = add nsw i32 %84, 2
%86 = load i32, i32* %15
%87 = add nsw i32 %86, 3
%88 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %81, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %83, i32 %85, i32 %87)
store i32 %88, i32* %17
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%90 = load i32, i32* %17
%91 = load i32*, i32** %9
%92 = call i32 @fwrite(i8* %89, i32 %90, i32 1, i32* %91)
%93 = icmp ne i32 %92, 1
br i1 %93, label %94, label %101
94: ; preds = %80
%95 = load i32*, i32** %9
%96 = call i32 @fclose(i32* %95)
%97 = load i32, i32* @stderr
%98 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %97)
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %80
br label %102
102: ; preds = %101
%103 = load i32, i32* %15
%104 = add nsw i32 %103, 3
store i32 %104, i32* %15
br label %76
105: ; preds = %76
%106 = load i32*, i32** %9
%107 = call i32 @fclose(i32* %106)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"v \00"
@.str.2 = [6 x i8] c"%.6f \00"
@.str.3 = [47 x i8] c"ERR: write capture data: failed to write file.\00"
@stderr = global i32 0
@.str.5 = [12 x i8] c"f %d %d %d\0A\00"
define void @obj_write(i8* nocapture %0, i32 %1, i32 %2, float* nocapture %3) {
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %51
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%14 = sext i32 %1 to i64
%15 = zext i32 %2 to i64
%16 = zext i32 %1 to i64
br label %24
17: ; preds = %4
%18 = tail call i32 @perror(i8* %0)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %29
br i1 %10, label %22, label %51
22: ; preds = %21
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
br label %53
24: ; preds = %11, %29
%25 = phi i64 [ 0, %11 ], [ %31, %29 ]
%26 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 1, i32* %7)
br i1 %12, label %27, label %29
27: ; preds = %24
%28 = mul nsw i64 %25, %14
br label %33
29: ; preds = %48, %24
%30 = call i32 @fputc(i32 10, i32* %7)
%31 = add nuw nsw i64 %25, 1
%32 = icmp eq i64 %31, %15
br i1 %32, label %21, label %24
33: ; preds = %27, %48
%34 = phi i64 [ 0, %27 ], [ %49, %48 ]
%35 = add nsw i64 %34, %28
%36 = getelementptr inbounds float, float* %3, i64 %35
%37 = load float, float* %36
%38 = fptosi float %37 to i32
%39 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %13, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 @fwrite(i8* %13, i32 %39, i32 1, i32* %7)
%41 = icmp eq i32 %40, 1
br i1 %41, label %48, label %42
42: ; preds = %33
%43 = call i32 @fclose(i32* %7)
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %33
%49 = add nuw nsw i64 %34, 1
%50 = icmp eq i64 %49, %16
br i1 %50, label %29, label %33
51: ; preds = %67, %9, %21
%52 = call i32 @fclose(i32* %7)
ret void
53: ; preds = %22, %67
%54 = phi i32 [ 0, %22 ], [ %57, %67 ]
%55 = add nuw nsw i32 %54, 1
%56 = add nuw nsw i32 %54, 2
%57 = add nuw nsw i32 %54, 3
%58 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %23, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %55, i32 %56, i32 %57)
%59 = call i32 @fwrite(i8* %23, i32 %58, i32 1, i32* %7)
%60 = icmp eq i32 %59, 1
br i1 %60, label %67, label %61
61: ; preds = %53
%62 = call i32 @fclose(i32* %7)
%63 = load i32, i32* @stderr
%64 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %63)
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %53
%68 = icmp slt i32 %57, %2
br i1 %68, label %53, label %51
}