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

/* Variables and functions */
int /*<<< orphan*/ lib3ds_matrix_identity(float **);
int /*<<< orphan*/ lib3ds_matrix_mult(float **, float **, float **);
int /*<<< orphan*/ lib3ds_matrix_rotate(float **, float, int /*<<< orphan*/,
                                        int, int /*<<< orphan*/);
int /*<<< orphan*/ lib3ds_matrix_translate(float **, float, float, float);
int /*<<< orphan*/ lib3ds_vector_cross(float *, float *, float *);
int /*<<< orphan*/ lib3ds_vector_normalize(float *);
int /*<<< orphan*/ lib3ds_vector_sub(float *, float *, float *);
void lib3ds_matrix_camera(float matrix[4][4], float pos[3], float tgt[3],
                          float roll) {
  float M[4][4];
  float x[3], y[3], z[3];
  lib3ds_vector_sub(y, tgt, pos);
  lib3ds_vector_normalize(y);
  if (y[0] != 0. || y[1] != 0) {
    z[0] = 0;
    z[1] = 0;
    z[2] = 1.0;
  } else {
    z[0] = -1.0;
    z[1] = 0;
    z[2] = 0;
  }
  lib3ds_vector_cross(x, y, z);
  lib3ds_vector_cross(z, x, y);
  lib3ds_vector_normalize(x);
  lib3ds_vector_normalize(z);
  lib3ds_matrix_identity(M);
  M[0][0] = x[0];
  M[1][0] = x[1];
  M[2][0] = x[2];
  M[0][1] = y[0];
  M[1][1] = y[1];
  M[2][1] = y[2];
  M[0][2] = z[0];
  M[1][2] = z[1];
  M[2][2] = z[2];
  lib3ds_matrix_identity(matrix);
  lib3ds_matrix_rotate(matrix, roll, 0, 1, 0);
  lib3ds_matrix_mult(matrix, matrix, M);
  lib3ds_matrix_translate(matrix, -pos[0], -pos[1], -pos[2]);
}


x86 assembly (clang, -O0):
<lib3ds_matrix_camera>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
lea    -0x78(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <lib3ds_vector_sub@plt>
lea    -0x78(%rbp),%rdi
call   1090 <lib3ds_vector_normalize@plt>
movss  -0x78(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <lib3ds_matrix_camera+0x6e>
jp     11de <lib3ds_matrix_camera+0x6e>
movss  -0x74(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11de <lib3ds_matrix_camera+0x6e>
jp     11de <lib3ds_matrix_camera+0x6e>
jmp    1203 <lib3ds_matrix_camera+0x93>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
xorps  %xmm0,%xmm0
movss  %xmm0,-0x80(%rbp)
movss  0xe0b(%rip),%xmm0
movss  %xmm0,-0x7c(%rbp)
jmp    1223 <lib3ds_matrix_camera+0xb3>
movss  0xdf5(%rip),%xmm0
movss  %xmm0,-0x84(%rbp)
ff
xorps  %xmm0,%xmm0
movss  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x7c(%rbp)
lea    -0x6c(%rbp),%rdi
lea    -0x78(%rbp),%rsi
lea    -0x84(%rbp),%rdx
call   1070 <lib3ds_vector_cross@plt>
lea    -0x84(%rbp),%rdi
lea    -0x6c(%rbp),%rsi
lea    -0x78(%rbp),%rdx
call   1070 <lib3ds_vector_cross@plt>
lea    -0x6c(%rbp),%rdi
call   1090 <lib3ds_vector_normalize@plt>
lea    -0x84(%rbp),%rdi
call   1090 <lib3ds_vector_normalize@plt>
lea    -0x60(%rbp),%rdi
call   1050 <lib3ds_matrix_identity@plt>
movss  -0x6c(%rbp),%xmm0
movss  %xmm0,-0x60(%rbp)
movss  -0x68(%rbp),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x64(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x78(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x74(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x70(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x84(%rbp),%xmm0
ff
movss  %xmm0,-0x58(%rbp)
movss  -0x80(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x7c(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <lib3ds_matrix_identity@plt>
mov    -0x8(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
xor    %ecx,%ecx
mov    $0x1,%edx
mov    %ecx,%esi
call   1080 <lib3ds_matrix_rotate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <lib3ds_matrix_mult@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm2
movd   %xmm2,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm2
call   1040 <lib3ds_matrix_translate@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib3ds_matrix_camera>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
movss  %xmm0,0x14(%rsp)
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x18(%rsp),%r15
mov    %r15,%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1060 <lib3ds_vector_sub@plt>
mov    %r15,%rdi
call   1090 <lib3ds_vector_normalize@plt>
xorps  %xmm0,%xmm0
ucomiss 0x18(%rsp),%xmm0
setp   %al
setne  %cl
or     %al,%cl
ucomiss 0x1c(%rsp),%xmm0
setp   %al
setne  %dl
or     %al,%dl
or     %cl,%dl
xorps  %xmm1,%xmm1
test   %dl,%dl
jne    11d2 <lib3ds_matrix_camera+0x62>
movss  0xe2e(%rip),%xmm1
je     11dc <lib3ds_matrix_camera+0x6c>
movss  0xe28(%rip),%xmm0
movss  %xmm1,0x8(%rsp)
movl   $0x0,0xc(%rsp)
movss  %xmm0,0x10(%rsp)
lea    0x24(%rsp),%rbx
lea    0x8(%rsp),%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1070 <lib3ds_vector_cross@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <lib3ds_vector_cross@plt>
mov    %rbx,%rdi
call   1090 <lib3ds_vector_normalize@plt>
mov    %r13,%rdi
call   1090 <lib3ds_vector_normalize@plt>
lea    0x30(%rsp),%r15
mov    %r15,%rdi
call   1050 <lib3ds_matrix_identity@plt>
movss  0x24(%rsp),%xmm0
movss  0x28(%rsp),%xmm1
movss  %xmm0,0x30(%rsp)
movss  %xmm1,0x40(%rsp)
movss  0x2c(%rsp),%xmm0
movss  %xmm0,0x50(%rsp)
movss  0x18(%rsp),%xmm0
movss  0x1c(%rsp),%xmm1
movss  %xmm0,0x34(%rsp)
movss  %xmm1,0x44(%rsp)
movss  0x20(%rsp),%xmm0
movss  %xmm0,0x54(%rsp)
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movss  %xmm0,0x38(%rsp)
movss  %xmm1,0x48(%rsp)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0x58(%rsp)
mov    %r12,%rdi
call   1050 <lib3ds_matrix_identity@plt>
mov    %r12,%rdi
movss  0x14(%rsp),%xmm0
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1080 <lib3ds_matrix_rotate@plt>
mov    %r12,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <lib3ds_matrix_mult@plt>
movss  (%r14),%xmm0
movss  0x4(%r14),%xmm1
movss  0x8(%r14),%xmm2
movaps 0xd2c(%rip),%xmm3
xorps  %xmm3,%xmm0
xorps  %xmm3,%xmm1
xorps  %xmm3,%xmm2
mov    %r12,%rdi
call   1040 <lib3ds_matrix_translate@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @lib3ds_matrix_camera([4 x float]* %0, float* %1, float* %2, float %3) {
%5 = alloca [4 x float]*
%6 = alloca float*
%7 = alloca float*
%8 = alloca float
%9 = alloca [4 x [4 x float]]
%10 = alloca [3 x float]
%11 = alloca [3 x float]
%12 = alloca [3 x float]
store [4 x float]* %0, [4 x float]** %5
store float* %1, float** %6
store float* %2, float** %7
store float %3, float* %8
%13 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%14 = load float*, float** %7
%15 = load float*, float** %6
%16 = call i32 @lib3ds_vector_sub(float* %13, float* %14, float* %15)
%17 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%18 = call i32 @lib3ds_vector_normalize(float* %17)
%19 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%20 = load float, float* %19
%21 = fpext float %20 to double
%22 = fcmp une double %21, 0.000000e+00
br i1 %22, label %27, label %23
23: ; preds = %4
%24 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 1
%25 = load float, float* %24
%26 = fcmp une float %25, 0.000000e+00
br i1 %26, label %27, label %31
27: ; preds = %23, %4
%28 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
store float 0.000000e+00, float* %28
%29 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 1
store float 0.000000e+00, float* %29
%30 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 2
store float 1.000000e+00, float* %30
br label %35
31: ; preds = %23
%32 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
store float -1.000000e+00, float* %32
%33 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 1
store float 0.000000e+00, float* %33
%34 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 2
store float 0.000000e+00, float* %34
br label %35
35: ; preds = %31, %27
%36 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%37 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%38 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%39 = call i32 @lib3ds_vector_cross(float* %36, float* %37, float* %38)
%40 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%41 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%42 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%43 = call i32 @lib3ds_vector_cross(float* %40, float* %41, float* %42)
%44 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%45 = call i32 @lib3ds_vector_normalize(float* %44)
%46 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%47 = call i32 @lib3ds_vector_normalize(float* %46)
%48 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 0
%49 = bitcast [4 x float]* %48 to float**
%50 = call i32 @lib3ds_matrix_identity(float** %49)
%51 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%52 = load float, float* %51
%53 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 0
%54 = getelementptr inbounds [4 x float], [4 x float]* %53, i64 0, i64 0
store float %52, float* %54
%55 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%56 = load float, float* %55
%57 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 1
%58 = getelementptr inbounds [4 x float], [4 x float]* %57, i64 0, i64 0
store float %56, float* %58
%59 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
%60 = load float, float* %59
%61 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 2
%62 = getelementptr inbounds [4 x float], [4 x float]* %61, i64 0, i64 0
store float %60, float* %62
%63 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%64 = load float, float* %63
%65 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 0
%66 = getelementptr inbounds [4 x float], [4 x float]* %65, i64 0, i64 1
store float %64, float* %66
%67 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 1
%68 = load float, float* %67
%69 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 1
%70 = getelementptr inbounds [4 x float], [4 x float]* %69, i64 0, i64 1
store float %68, float* %70
%71 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 2
%72 = load float, float* %71
%73 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 2
%74 = getelementptr inbounds [4 x float], [4 x float]* %73, i64 0, i64 1
store float %72, float* %74
%75 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 0
%76 = load float, float* %75
%77 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 0
%78 = getelementptr inbounds [4 x float], [4 x float]* %77, i64 0, i64 2
store float %76, float* %78
%79 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 1
%80 = load float, float* %79
%81 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 1
%82 = getelementptr inbounds [4 x float], [4 x float]* %81, i64 0, i64 2
store float %80, float* %82
%83 = getelementptr inbounds [3 x float], [3 x float]* %12, i64 0, i64 2
%84 = load float, float* %83
%85 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 2
%86 = getelementptr inbounds [4 x float], [4 x float]* %85, i64 0, i64 2
store float %84, float* %86
%87 = load [4 x float]*, [4 x float]** %5
%88 = bitcast [4 x float]* %87 to float**
%89 = call i32 @lib3ds_matrix_identity(float** %88)
%90 = load [4 x float]*, [4 x float]** %5
%91 = bitcast [4 x float]* %90 to float**
%92 = load float, float* %8
%93 = call i32 @lib3ds_matrix_rotate(float** %91, float %92, i32 0, i32 1, i32 0)
%94 = load [4 x float]*, [4 x float]** %5
%95 = bitcast [4 x float]* %94 to float**
%96 = load [4 x float]*, [4 x float]** %5
%97 = bitcast [4 x float]* %96 to float**
%98 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %9, i64 0, i64 0
%99 = bitcast [4 x float]* %98 to float**
%100 = call i32 @lib3ds_matrix_mult(float** %95, float** %97, float** %99)
%101 = load [4 x float]*, [4 x float]** %5
%102 = bitcast [4 x float]* %101 to float**
%103 = load float*, float** %6
%104 = getelementptr inbounds float, float* %103, i64 0
%105 = load float, float* %104
%106 = fneg float %105
%107 = load float*, float** %6
%108 = getelementptr inbounds float, float* %107, i64 1
%109 = load float, float* %108
%110 = fneg float %109
%111 = load float*, float** %6
%112 = getelementptr inbounds float, float* %111, i64 2
%113 = load float, float* %112
%114 = fneg float %113
%115 = call i32 @lib3ds_matrix_translate(float** %102, float %106, float %110, float %114)
ret void
}

LLVM IR (-O2):
define void @lib3ds_matrix_camera([4 x float]* %0, float* %1, float* %2, float %3) {
%5 = alloca [4 x [4 x float]]
%6 = alloca [3 x float]
%7 = alloca [3 x float]
%8 = alloca [3 x float]
%9 = bitcast [4 x [4 x float]]* %5 to i8*
%10 = bitcast [3 x float]* %6 to i8*
%11 = bitcast [3 x float]* %7 to i8*
%12 = bitcast [3 x float]* %8 to i8*
%13 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%14 = call i32 @lib3ds_vector_sub(float* %13, float* %2, float* %1)
%15 = call i32 @lib3ds_vector_normalize(float* %13)
%16 = load float, float* %13
%17 = fcmp une float %16, 0.000000e+00
%18 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%19 = load float, float* %18
%20 = fcmp une float %19, 0.000000e+00
%21 = select i1 %17, i1 true, i1 %20
%22 = select i1 %21, float 0.000000e+00, float -1.000000e+00
%23 = select i1 %21, float 1.000000e+00, float 0.000000e+00
%24 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 0
store float %22, float* %24
%25 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 1
store float 0.000000e+00, float* %25
%26 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 2
store float %23, float* %26
%27 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%28 = call i32 @lib3ds_vector_cross(float* %27, float* %13, float* %24)
%29 = call i32 @lib3ds_vector_cross(float* %24, float* %27, float* %13)
%30 = call i32 @lib3ds_vector_normalize(float* %27)
%31 = call i32 @lib3ds_vector_normalize(float* %24)
%32 = bitcast [4 x [4 x float]]* %5 to float**
%33 = call i32 @lib3ds_matrix_identity(float** %32)
%34 = load float, float* %27
%35 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 0, i64 0
store float %34, float* %35
%36 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 1
%37 = load float, float* %36
%38 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 1, i64 0
store float %37, float* %38
%39 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 2
%40 = load float, float* %39
%41 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 2, i64 0
store float %40, float* %41
%42 = load float, float* %13
%43 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 0, i64 1
store float %42, float* %43
%44 = load float, float* %18
%45 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 1, i64 1
store float %44, float* %45
%46 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 2
%47 = load float, float* %46
%48 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 2, i64 1
store float %47, float* %48
%49 = load float, float* %24
%50 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 0, i64 2
store float %49, float* %50
%51 = load float, float* %25
%52 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 1, i64 2
store float %51, float* %52
%53 = load float, float* %26
%54 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %5, i64 0, i64 2, i64 2
store float %53, float* %54
%55 = bitcast [4 x float]* %0 to float**
%56 = call i32 @lib3ds_matrix_identity(float** %55)
%57 = call i32 @lib3ds_matrix_rotate(float** %55, float %3, i32 0, i32 1, i32 0)
%58 = call i32 @lib3ds_matrix_mult(float** %55, float** %55, float** %32)
%59 = load float, float* %1
%60 = fneg float %59
%61 = getelementptr inbounds float, float* %1, i64 1
%62 = load float, float* %61
%63 = fneg float %62
%64 = getelementptr inbounds float, float* %1, i64 2
%65 = load float, float* %64
%66 = fneg float %65
%67 = call i32 @lib3ds_matrix_translate(float** %55, float %60, float %63, float %66)
ret void
}