#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 displaz_fwrite_ply(int /*<<< orphan*/ *, size_t, double *, float *,
                       float *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int displaz_write_ply(const char *fileName, size_t npoints, double *position,
                      float *color, float *normal) {
  FILE *ply = fopen(fileName, "w");
  if (!ply)
    return 0;
  int ret = displaz_fwrite_ply(ply, npoints, position, color, normal);
  fclose(ply);
  return ret;
}


x86 assembly (clang, -O0):
<displaz_write_ply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1177 <displaz_write_ply+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <displaz_write_ply+0x72>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <displaz_fwrite_ply@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displaz_write_ply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117d <displaz_write_ply+0x4d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <displaz_fwrite_ply@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    117f <displaz_write_ply+0x4f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
define i32 @displaz_write_ply(i8* %0, i64 %1, double* %2, float* %3, float* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca double*
%10 = alloca float*
%11 = alloca float*
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store double* %2, double** %9
store float* %3, float** %10
store float* %4, float** %11
%14 = load i8*, i8** %7
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %5
store i32 0, i32* %6
br label %29
19: ; preds = %5
%20 = load i32*, i32** %12
%21 = load i64, i64* %8
%22 = load double*, double** %9
%23 = load float*, float** %10
%24 = load float*, float** %11
%25 = call i32 @displaz_fwrite_ply(i32* %20, i64 %21, double* %22, float* %23, float* %24)
store i32 %25, i32* %13
%26 = load i32*, i32** %12
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %13
store i32 %28, i32* %6
br label %29
29: ; preds = %19, %18
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define i32 @displaz_write_ply(i8* nocapture %0, i64 %1, double* %2, float* %3, float* %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @displaz_fwrite_ply(i32* %6, i64 %1, double* %2, float* %3, float* %4)
%10 = tail call i32 @fclose(i32* %6)
br label %11
11: ; preds = %5, %8
%12 = phi i32 [ %9, %8 ], [ 0, %5 ]
ret i32 %12
}