#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 */
scalar_t__ img_is_float(struct img_pixmap *);
int /*<<< orphan*/ img_setpixel(struct img_pixmap *, int, int, unsigned char *);
int /*<<< orphan*/ img_setpixel4f(struct img_pixmap *, int, int, int, int, int,
                                  int);
void img_setpixel4i(struct img_pixmap *img, int x, int y, int r, int g, int b,
                    int a) {
  if (img_is_float(img)) {
    img_setpixel4f(img, x, y, r / 255.0, g / 255.0, b / 255.0, a / 255.0);
  } else {
    unsigned char pixel[4];
    pixel[0] = r;
    pixel[1] = g;
    pixel[2] = b;
    pixel[3] = a;
    img_setpixel(img, x, y, pixel);
  }
}


x86 assembly (clang, -O0):
<img_setpixel4i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <img_is_float@plt>
cmp    $0x0,%rax
je     11d0 <img_setpixel4i+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe71(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r8d
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe5b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r9d
cvtsi2sdl 0x10(%rbp),%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%rsp)
call   1030 <img_setpixel4f@plt>
jmp    11fb <img_setpixel4i+0xcb>
mov    -0x14(%rbp),%eax
mov    %al,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x1f(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x1e(%rbp)
mov    0x10(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1050 <img_setpixel@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<img_setpixel4i>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
call   1040 <img_is_float@plt>
test   %rax,%rax
je     11b3 <img_setpixel4i+0x83>
cvtsi2sd %ebp,%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r8d
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r9d
xorps  %xmm0,%xmm0
cvtsi2sdl 0x50(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <img_setpixel4f@plt>
jmp    11dd <img_setpixel4i+0xad>
mov    %bpl,0x14(%rsp)
mov    %r13b,0x15(%rsp)
mov    %r12b,0x16(%rsp)
mov    0x50(%rsp),%eax
mov    %al,0x17(%rsp)
lea    0x14(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1050 <img_setpixel@plt>
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_setpixel4i(%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 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
%16 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%17 = call i64 @img_is_float(%struct.img_pixmap* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %7
%20 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = load i32, i32* %11
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 2.550000e+02
%26 = fptosi double %25 to i32
%27 = load i32, i32* %12
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 2.550000e+02
%30 = fptosi double %29 to i32
%31 = load i32, i32* %13
%32 = sitofp i32 %31 to double
%33 = fdiv double %32, 2.550000e+02
%34 = fptosi double %33 to i32
%35 = load i32, i32* %14
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, 2.550000e+02
%38 = fptosi double %37 to i32
%39 = call i32 @img_setpixel4f(%struct.img_pixmap* %20, i32 %21, i32 %22, i32 %26, i32 %30, i32 %34, i32 %38)
br label %58
40: ; preds = %7
%41 = load i32, i32* %11
%42 = trunc i32 %41 to i8
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
store i8 %42, i8* %43
%44 = load i32, i32* %12
%45 = trunc i32 %44 to i8
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 1
store i8 %45, i8* %46
%47 = load i32, i32* %13
%48 = trunc i32 %47 to i8
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 2
store i8 %48, i8* %49
%50 = load i32, i32* %14
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 3
store i8 %51, i8* %52
%53 = load %struct.img_pixmap*, %struct.img_pixmap** %8
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%57 = call i32 @img_setpixel(%struct.img_pixmap* %53, i32 %54, i32 %55, i8* %56)
br label %58
58: ; preds = %40, %19
ret void
}

LLVM IR (-O2):
%struct.img_pixmap = type { i32 }
define void @img_setpixel4i(%struct.img_pixmap* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca [4 x i8]
%9 = tail call i64 @img_is_float(%struct.img_pixmap* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %7
%12 = sitofp i32 %3 to double
%13 = fdiv double %12, 2.550000e+02
%14 = fptosi double %13 to i32
%15 = sitofp i32 %4 to double
%16 = fdiv double %15, 2.550000e+02
%17 = fptosi double %16 to i32
%18 = sitofp i32 %5 to double
%19 = fdiv double %18, 2.550000e+02
%20 = fptosi double %19 to i32
%21 = sitofp i32 %6 to double
%22 = fdiv double %21, 2.550000e+02
%23 = fptosi double %22 to i32
%24 = tail call i32 @img_setpixel4f(%struct.img_pixmap* %0, i32 %1, i32 %2, i32 %14, i32 %17, i32 %20, i32 %23)
br label %35
25: ; preds = %7
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%27 = trunc i32 %3 to i8
store i8 %27, i8* %26
%28 = trunc i32 %4 to i8
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 %28, i8* %29
%30 = trunc i32 %5 to i8
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 %30, i8* %31
%32 = trunc i32 %6 to i8
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 %32, i8* %33
%34 = call i32 @img_setpixel(%struct.img_pixmap* %0, i32 %1, i32 %2, i8* %26)
br label %35
35: ; preds = %25, %11
ret void
}