#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_getpixel4i(struct img_pixmap *img, int x, int y, int *r, int *g,
                    int *b, int *a) {
  if (img_is_float(img)) {
    float pixel[4] = {0, 0, 0, 0};
    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;
  } else {
    unsigned char pixel[4];
    img_getpixel(img, x, y, pixel);
    *r = pixel[0];
    *g = pixel[1];
    *b = pixel[2];
    *a = pixel[3];
  }
}


x86 assembly (clang, -O0):
<img_getpixel4i>:
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     120b <img_getpixel4i+0xdb>
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
cvtss2sd %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe46(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe27(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe08(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1248 <img_getpixel4i+0x118>
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),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x43(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x42(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x41(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<img_getpixel4i>:
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     11bd <img_getpixel4i+0x9d>
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
cvtss2sd %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r12)
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r15)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r14)
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
jmp    11ec <img_getpixel4i+0xcc>
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <img_getpixel@plt>
movzbl (%rsp),%eax
mov    %eax,(%r12)
movzbl 0x1(%rsp),%eax
mov    %eax,(%r15)
movzbl 0x2(%rsp),%eax
mov    %eax,(%r14)
movzbl 0x3(%rsp),%eax
mov    0x50(%rsp),%rcx
mov    %eax,(%rcx)
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_getpixel4i(%struct.img_pixmap* %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = alloca %struct.img_pixmap*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%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 i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store i32* %6, i32** %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 %51
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 = fpext float %28 to double
%30 = fmul double %29, 2.550000e+02
%31 = fptosi double %30 to i32
%32 = load i32*, i32** %11
store i32 %31, i32* %32
%33 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 1
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = fmul double %35, 2.550000e+02
%37 = fptosi double %36 to i32
%38 = load i32*, i32** %12
store i32 %37, i32* %38
%39 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 2
%40 = load float, float* %39
%41 = fpext float %40 to double
%42 = fmul double %41, 2.550000e+02
%43 = fptosi double %42 to i32
%44 = load i32*, i32** %13
store i32 %43, i32* %44
%45 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 3
%46 = load float, float* %45
%47 = fpext float %46 to double
%48 = fmul double %47, 2.550000e+02
%49 = fptosi double %48 to i32
%50 = load i32*, i32** %14
store i32 %49, i32* %50
br label %73
51: ; preds = %7
%52 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%53 = load i32, i32* %9
%54 = load i32, i32* %10
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%56 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %52, i32 %53, i32 %54, i8* %55)
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = load i32*, i32** %11
store i32 %59, i32* %60
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 1
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = load i32*, i32** %12
store i32 %63, i32* %64
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 2
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = load i32*, i32** %13
store i32 %67, i32* %68
%69 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 3
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = load i32*, i32** %14
store i32 %71, i32* %72
br label %73
73: ; preds = %51, %20
ret void
}

LLVM IR (-O2):
%struct.img_pixmap = type { i32 }
define void @img_getpixel4i(%struct.img_pixmap* %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32* 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 %35, 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
%17 = fpext float %16 to double
%18 = fmul double %17, 2.550000e+02
%19 = fptosi double %18 to i32
store i32 %19, i32* %3
%20 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 1
%21 = load float, float* %20
%22 = fpext float %21 to double
%23 = fmul double %22, 2.550000e+02
%24 = fptosi double %23 to i32
store i32 %24, i32* %4
%25 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 2
%26 = load float, float* %25
%27 = fpext float %26 to double
%28 = fmul double %27, 2.550000e+02
%29 = fptosi double %28 to i32
store i32 %29, i32* %5
%30 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 3
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = fmul double %32, 2.550000e+02
%34 = fptosi double %33 to i32
store i32 %34, i32* %6
br label %49
35: ; preds = %7
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%37 = call i32 (%struct.img_pixmap*, i32, i32, ...) @img_getpixel(%struct.img_pixmap* %0, i32 %1, i32 %2, i8* %36)
%38 = load i8, i8* %36
%39 = zext i8 %38 to i32
store i32 %39, i32* %3
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
store i32 %42, i32* %4
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
store i32 %45, i32* %5
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
store i32 %48, i32* %6
br label %49
49: ; preds = %35, %12
ret void
}