#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 */
struct img_pixmap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ img_getpixel(struct img_pixmap *, int, int, ...);
scalar_t__ img_is_float(struct img_pixmap *);
void img_getpixel4f(struct img_pixmap *img, int x, int y, float *r, float *g,
                    float *b, float *a) {
  if (img_is_float(img)) {
    float pixel[4] = {0, 0, 0, 0};
    img_getpixel(img, x, y, pixel);
    *r = pixel[0];
    *g = pixel[1];
    *b = pixel[2];
    *a = pixel[3];
  } else {
    unsigned char pixel[4];
    img_getpixel(img, x, y, pixel);
    *r = pixel[0] / 255.0;
    *g = pixel[1] / 255.0;
    *b = pixel[2] / 255.0;
    *a = pixel[3] / 255.0;
  }
}


x86 assembly (clang, -O0):
<img_getpixel4f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <img_is_float@plt>
cmp    $0x0,%rax
je     11c3 <img_getpixel4f+0x93>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x40(%rbp),%rcx
mov    $0x0,%al
call   1040 <img_getpixel@plt>
movss  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x3c(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x34(%rbp),%xmm0
mov    0x10(%rbp),%rax
movss  %xmm0,(%rax)
jmp    1258 <img_getpixel4f+0x128>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x44(%rbp),%rcx
mov    $0x0,%al
call   1040 <img_getpixel@plt>
movzbl -0x44(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe18(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movzbl -0x43(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdf8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movzbl -0x42(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdd8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movzbl -0x41(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    0x10(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<img_getpixel4f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%rbp
call   1040 <img_is_float@plt>
test   %rax,%rax
je     118b <img_getpixel4f+0x6b>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <img_getpixel@plt>
movss  (%rsp),%xmm0
movss  %xmm0,(%r12)
movss  0x4(%rsp),%xmm0
movss  %xmm0,(%r15)
movss  0x8(%rsp),%xmm0
movss  %xmm0,(%r14)
movss  0xc(%rsp),%xmm0
jmp    1201 <img_getpixel4f+0xe1>
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <img_getpixel@plt>
movzbl (%rsp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe53(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r12)
movzbl 0x1(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r15)
movzbl 0x2(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r14)
movzbl 0x3(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    0x50(%rsp),%rax
movss  %xmm0,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.img_pixmap = type { i32 }
define void @img_getpixel4f(%struct.img_pixmap* %0, i32 %1, i32 %2, float* %3, float* %4, float* %5, float* %6) {
%8 = alloca %struct.img_pixmap*
%9 = alloca i32
%10 = alloca i32
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca [4 x float]
%16 = alloca [4 x i8]
store %struct.img_pixmap* %0, %struct.img_pixmap** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store float* %3, float** %11
store float* %4, float** %12
store float* %5, float** %13
store float* %6, float** %14
%17 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%18 = call i64 @img_is_float(%struct.img_pixmap* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %7
%21 = bitcast [4 x float]* %15 to i8*
%22 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 0
%26 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %22, i32 %23, i32 %24, float* %25)
%27 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 0
%28 = load float, float* %27
%29 = load float*, float** %11
store float %28, float* %29
%30 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 1
%31 = load float, float* %30
%32 = load float*, float** %12
store float %31, float* %32
%33 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 2
%34 = load float, float* %33
%35 = load float*, float** %13
store float %34, float* %35
%36 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 3
%37 = load float, float* %36
%38 = load float*, float** %14
store float %37, float* %38
br label %73
39: ; preds = %7
%40 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%44 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %40, i32 %41, i32 %42, i8* %43)
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = sitofp i32 %47 to double
%49 = fdiv double %48, 2.550000e+02
%50 = fptrunc double %49 to float
%51 = load float*, float** %11
store float %50, float* %51
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = sitofp i32 %54 to double
%56 = fdiv double %55, 2.550000e+02
%57 = fptrunc double %56 to float
%58 = load float*, float** %12
store float %57, float* %58
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 2
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = sitofp i32 %61 to double
%63 = fdiv double %62, 2.550000e+02
%64 = fptrunc double %63 to float
%65 = load float*, float** %13
store float %64, float* %65
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 3
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = sitofp i32 %68 to double
%70 = fdiv double %69, 2.550000e+02
%71 = fptrunc double %70 to float
%72 = load float*, float** %14
store float %71, float* %72
br label %73
73: ; preds = %39, %20
ret void
}

LLVM IR (-O2):
%struct.img_pixmap = type { i32 }
define void @img_getpixel4f(%struct.img_pixmap* %0, i32 %1, i32 %2, float* nocapture writeonly %3, float* nocapture writeonly %4, float* nocapture writeonly %5, float* nocapture writeonly %6) {
%8 = alloca [4 x float]
%9 = alloca [4 x i8]
%10 = tail call i64 @img_is_float(%struct.img_pixmap* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %7
%13 = bitcast [4 x float]* %8 to i8*
%14 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 0
%15 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %0, i32 %1, i32 %2, float* %14)
%16 = load float, float* %14
store float %16, float* %3
%17 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 1
%18 = load float, float* %17
store float %18, float* %4
%19 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 2
%20 = load float, float* %19
store float %20, float* %5
%21 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 3
%22 = load float, float* %21
store float %22, float* %6
br label %45
23: ; preds = %7
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%25 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %0, i32 %1, i32 %2, i8* %24)
%26 = load i8, i8* %24
%27 = uitofp i8 %26 to double
%28 = fdiv double %27, 2.550000e+02
%29 = fptrunc double %28 to float
store float %29, float* %3
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%31 = load i8, i8* %30
%32 = uitofp i8 %31 to double
%33 = fdiv double %32, 2.550000e+02
%34 = fptrunc double %33 to float
store float %34, float* %4
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%36 = load i8, i8* %35
%37 = uitofp i8 %36 to double
%38 = fdiv double %37, 2.550000e+02
%39 = fptrunc double %38 to float
store float %39, float* %5
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%41 = load i8, i8* %40
%42 = uitofp i8 %41 to double
%43 = fdiv double %42, 2.550000e+02
%44 = fptrunc double %43 to float
store float %44, float* %6
br label %45
45: ; preds = %23, %12
ret void
}