#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*/ displaz_fwrite_ply(int /*<<< orphan*/ *, size_t, double *,
                                      float *, float *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int launch_displaz(char *, char *);
int mkstemps(char *, int);
int displaz_points(size_t npoints, double *position, float *color,
                   float *normal) {
  char fileName[] = "/tmp/displaz_c_XXXXXX.ply";
  int plyfd = mkstemps(fileName, 4);
  FILE *ply = fdopen(plyfd, "wb");
  if (!displaz_fwrite_ply(ply, npoints, position, color, normal))
    return 1;
  fclose(ply);
  return launch_displaz(fileName, "-rmtemp");
}


x86 assembly (clang, -O0):
<displaz_points>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0xe91(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe88(%rip),%ax
mov    %ax,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x4,%esi
call   1030 <mkstemps@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1050 <displaz_fwrite_ply@plt>
cmp    $0x0,%eax
jne    11e6 <displaz_points+0x96>
movl   $0x1,-0x4(%rbp)
jmp    1202 <displaz_points+0xb2>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x50(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1070 <launch_displaz@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displaz_points>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movups 0xe9a(%rip),%xmm0
movups %xmm0,0xa(%rsp)
movaps 0xe84(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x4,%esi
call   1030 <mkstemps@plt>
lea    0xe86(%rip),%rsi
mov    %eax,%edi
call   1060 <fdopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <displaz_fwrite_ply@plt>
test   %eax,%eax
je     11cf <displaz_points+0x7f>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe58(%rip),%rsi
mov    %rsp,%rdi
call   1070 <launch_displaz@plt>
jmp    11d4 <displaz_points+0x84>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.displaz_points.fileName = [26 x i8] c"/tmp/displaz_c_XXXXXX.ply\00"
@.str = [3 x i8] c"wb\00"
@.str.1 = [8 x i8] c"-rmtemp\00"
define i32 @displaz_points(i64 %0, double* %1, float* %2, float* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca double*
%8 = alloca float*
%9 = alloca float*
%10 = alloca [26 x i8]
%11 = alloca i32
%12 = alloca i32*
store i64 %0, i64* %6
store double* %1, double** %7
store float* %2, float** %8
store float* %3, float** %9
%13 = bitcast [26 x i8]* %10 to i8*
%14 = getelementptr inbounds [26 x i8], [26 x i8]* %10, i64 0, i64 0
%15 = call i32 @mkstemps(i8* %14, i32 4)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = call i32* @fdopen(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %12
%18 = load i32*, i32** %12
%19 = load i64, i64* %6
%20 = load double*, double** %7
%21 = load float*, float** %8
%22 = load float*, float** %9
%23 = call i32 @displaz_fwrite_ply(i32* %18, i64 %19, double* %20, float* %21, float* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %4
store i32 1, i32* %5
br label %31
26: ; preds = %4
%27 = load i32*, i32** %12
%28 = call i32 @fclose(i32* %27)
%29 = getelementptr inbounds [26 x i8], [26 x i8]* %10, i64 0, i64 0
%30 = call i32 @launch_displaz(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %30, i32* %5
br label %31
31: ; preds = %26, %25
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@__const.displaz_points.fileName = [26 x i8] c"/tmp/displaz_c_XXXXXX.ply\00"
@.str = [3 x i8] c"wb\00"
@.str.1 = [8 x i8] c"-rmtemp\00"
define i32 @displaz_points(i64 %0, double* %1, float* %2, float* %3) {
%5 = alloca [26 x i8]
%6 = getelementptr inbounds [26 x i8], [26 x i8]* %5, i64 0, i64 0
%7 = call i32 @mkstemps(i8* %6, i32 4)
%8 = call i32* @fdopen(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @displaz_fwrite_ply(i32* %8, i64 %0, double* %1, float* %2, float* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = call i32 @fclose(i32* %8)
%13 = call i32 @launch_displaz(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %4, %11
%15 = phi i32 [ %13, %11 ], [ 1, %4 ]
ret i32 %15
}