#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 GLfloat;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sqrt(int);
int /*<<< orphan*/ stderr;
void normalize(GLfloat v[3]) {
  GLfloat d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (d == 0)
    fprintf(stderr, "Zero length vector in normalize\n");
  else
    v[0] /= d;
  v[1] /= d;
  v[2] /= d;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
imul   (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
imul   0x4(%rcx),%eax
add    %eax,%edi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x8(%rbp),%rcx
imul   0x8(%rcx),%eax
add    %eax,%edi
call   1040 <sqrt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1187 <normalize+0x67>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
jmp    119f <normalize+0x7f>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    (%rax),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x4(%rax),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x8(%rax),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
imul   %eax,%eax
imul   %ecx,%ecx
add    %eax,%ecx
mov    0x8(%rdi),%edi
imul   %edi,%edi
add    %ecx,%edi
call   1040 <sqrt@plt>
mov    %eax,%ebp
test   %eax,%eax
je     114f <normalize+0x2f>
mov    (%rbx),%eax
cltd
idiv   %ebp
mov    %eax,(%rbx)
jmp    1164 <normalize+0x44>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x4(%rbx),%eax
mov    0x8(%rbx),%ecx
cltd
idiv   %ebp
mov    %eax,0x4(%rbx)
mov    %ecx,%eax
cltd
idiv   %ebp
mov    %eax,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Zero length vector in normalize\0A\00"
define void @normalize(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = getelementptr inbounds i32, i32* %4, i64 0
%6 = load i32, i32* %5
%7 = load i32*, i32** %2
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = mul nsw i32 %6, %9
%11 = load i32*, i32** %2
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = mul nsw i32 %13, %16
%18 = add nsw i32 %10, %17
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i64 2
%21 = load i32, i32* %20
%22 = load i32*, i32** %2
%23 = getelementptr inbounds i32, i32* %22, i64 2
%24 = load i32, i32* %23
%25 = mul nsw i32 %21, %24
%26 = add nsw i32 %18, %25
%27 = call i32 @sqrt(i32 %26)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %1
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %39
33: ; preds = %1
%34 = load i32, i32* %3
%35 = load i32*, i32** %2
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = sdiv i32 %37, %34
store i32 %38, i32* %36
br label %39
39: ; preds = %33, %30
%40 = load i32, i32* %3
%41 = load i32*, i32** %2
%42 = getelementptr inbounds i32, i32* %41, i64 1
%43 = load i32, i32* %42
%44 = sdiv i32 %43, %40
store i32 %44, i32* %42
%45 = load i32, i32* %3
%46 = load i32*, i32** %2
%47 = getelementptr inbounds i32, i32* %46, i64 2
%48 = load i32, i32* %47
%49 = sdiv i32 %48, %45
store i32 %49, i32* %47
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Zero length vector in normalize\0A\00"
define void @normalize(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = mul nsw i32 %2, %2
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = mul nsw i32 %5, %5
%7 = add nuw nsw i32 %6, %3
%8 = getelementptr inbounds i32, i32* %0, i64 2
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, %9
%11 = add nuw nsw i32 %7, %10
%12 = tail call i32 @sqrt(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %1
%18 = load i32, i32* %0
%19 = sdiv i32 %18, %12
store i32 %19, i32* %0
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = sdiv i32 %21, %12
store i32 %22, i32* %4
%23 = load i32, i32* %8
%24 = sdiv i32 %23, %12
store i32 %24, i32* %8
ret void
}