#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*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(float *);
int /*<<< orphan*/ cross(float *, int /*<<< orphan*/ *, float *, size_t);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ normalize(float *, size_t);
int /*<<< orphan*/ normals(float *, int /*<<< orphan*/ *, float *, size_t);
void get_normals(float *vertices, uint16_t *triangles, float *normal_map,
                 size_t vertices_count, size_t triangles_count) {
  float *normal_vectors = (float *)malloc(3 * sizeof(float) * triangles_count);
  assert(normal_vectors);
  cross(vertices, triangles, normal_vectors, triangles_count);
  normals(normal_vectors, triangles, normal_map, triangles_count);
  normalize(normal_map, vertices_count);
  free(normal_vectors);
}


x86 assembly (clang, -O0):
<get_normals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
imul   $0xc,-0x28(%rbp),%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1080 <cross@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <normals@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <normalize@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_normals>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0x0(,%r8,4),%eax
lea    (%rax,%rax,2),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1080 <cross@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <normals@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <normalize@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @get_normals(float* %0, i32* %1, float* %2, i64 %3, i64 %4) {
%6 = alloca float*
%7 = alloca i32*
%8 = alloca float*
%9 = alloca i64
%10 = alloca i64
%11 = alloca float*
store float* %0, float** %6
store i32* %1, i32** %7
store float* %2, float** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%12 = load i64, i64* %10
%13 = mul i64 12, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to float*
store float* %16, float** %11
%17 = load float*, float** %11
%18 = call i32 @assert(float* %17)
%19 = load float*, float** %6
%20 = load i32*, i32** %7
%21 = load float*, float** %11
%22 = load i64, i64* %10
%23 = call i32 @cross(float* %19, i32* %20, float* %21, i64 %22)
%24 = load float*, float** %11
%25 = load i32*, i32** %7
%26 = load float*, float** %8
%27 = load i64, i64* %10
%28 = call i32 @normals(float* %24, i32* %25, float* %26, i64 %27)
%29 = load float*, float** %8
%30 = load i64, i64* %9
%31 = call i32 @normalize(float* %29, i64 %30)
%32 = load float*, float** %11
%33 = call i32 @free(float* %32)
ret void
}

LLVM IR (-O2):
define void @get_normals(float* %0, i32* %1, float* %2, i64 %3, i64 %4) {
%6 = trunc i64 %4 to i32
%7 = mul i32 %6, 12
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to float*
%10 = tail call i32 @assert(float* %9)
%11 = tail call i32 @cross(float* %0, i32* %1, float* %9, i64 %4)
%12 = tail call i32 @normals(float* %9, i32* %1, float* %2, i64 %4)
%13 = tail call i32 @normalize(float* %2, i64 %3)
%14 = tail call i32 @free(float* %9)
ret void
}