#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 /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ s2scr(int, float, float, float);
int /*<<< orphan*/ *texture_gen(char *, int, int, int /*<<< orphan*/);
int s2icm(char *imapname, int iidx1, int iidx2) {
  int32_t *colormap;
  int ncolors;
  int i;
  float r, g, b;
  unsigned char *obuf;
  ncolors = iidx2 - iidx1 + 1;
  colormap = texture_gen(imapname, 16, ncolors, 0);
  for (i = 0; i < ncolors; i++) {
    obuf = (unsigned char *)(colormap + 12 * ncolors + i);
    r = obuf[0] / 255.0;
    g = obuf[1] / 255.0;
    b = obuf[2] / 255.0;
    s2scr(iidx1 + i, r, g, b);
  }
  free(colormap);
  return (ncolors);
}


x86 assembly (clang, -O0):
<s2icm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x10,%esi
xor    %ecx,%ecx
call   1040 <texture_gen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1223 <s2icm+0xf3>
mov    -0x18(%rbp),%rax
imul   $0xc,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x38(%rbp),%rax
movzbl 0x1(%rax),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%rax
movzbl 0x2(%rax),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe12(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
add    -0x20(%rbp),%edi
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm2
call   1030 <s2scr@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <s2icm+0x3c>
mov    -0x18(%rbp),%rdi
call   1050 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s2icm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
sub    %esi,%ebx
lea    0x1(%rbx),%r15d
mov    $0x10,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1040 <texture_gen@plt>
mov    %rax,%r14
test   %ebx,%ebx
js     11d6 <s2icm+0xa6>
lea    0x0(,%r15,4),%eax
lea    (%rax,%rax,2),%eax
cltq
mov    %r15d,%r12d
mov    %ebp,%r13d
lea    (%r14,%rax,4),%rbx
add    $0x2,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl -0x2(%rbx,%rbp,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe6c(%rip),%xmm3
divsd  %xmm3,%xmm0
cvtsd2ss %xmm0,%xmm0
movzbl -0x1(%rbx,%rbp,4),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm3,%xmm1
cvtsd2ss %xmm1,%xmm1
movzbl (%rbx,%rbp,4),%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
divsd  %xmm3,%xmm2
cvtsd2ss %xmm2,%xmm2
lea    0x0(%r13,%rbp,1),%edi
call   1030 <s2scr@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1180 <s2icm+0x50>
mov    %r14,%rdi
call   1050 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @s2icm(i8* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = add nsw i32 %4, 1
%6 = tail call i32* @texture_gen(i8* %0, i32 16, i32 %5, i32 0)
%7 = icmp slt i32 %4, 0
br i1 %7, label %36, label %8
8: ; preds = %3
%9 = mul nsw i32 %5, 12
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %6, i64 %10
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %8, %13
%14 = phi i64 [ 0, %8 ], [ %34, %13 ]
%15 = getelementptr inbounds i32, i32* %11, i64 %14
%16 = bitcast i32* %15 to i8*
%17 = load i8, i8* %16
%18 = uitofp i8 %17 to double
%19 = fdiv double %18, 2.550000e+02
%20 = fptrunc double %19 to float
%21 = getelementptr inbounds i8, i8* %16, i64 1
%22 = load i8, i8* %21
%23 = uitofp i8 %22 to double
%24 = fdiv double %23, 2.550000e+02
%25 = fptrunc double %24 to float
%26 = getelementptr inbounds i8, i8* %16, i64 2
%27 = load i8, i8* %26
%28 = uitofp i8 %27 to double
%29 = fdiv double %28, 2.550000e+02
%30 = fptrunc double %29 to float
%31 = trunc i64 %14 to i32
%32 = add i32 %31, %1
%33 = tail call i32 @s2scr(i32 %32, float %20, float %25, float %30)
%34 = add nuw nsw i64 %14, 1
%35 = icmp eq i64 %34, %12
br i1 %35, label %36, label %13
36: ; preds = %13, %3
%37 = tail call i32 @free(i32* %6)
ret i32 %5
}