// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: DrawImageInset(ImageData*, double, double, double)
static void
DrawImageInset(ImageData *data,
  double x, double y, double scale)
{
  // Check if drawing image insets
  if (!show_image_insets) return;

  // Get convenient variables
  double w = scale * data->image_width;
  double h = scale * data->image_height;
  if ((w == 0) || (h == 0)) return;

  // Load texture
  LoadTexture(data);
  if (data->texture_id == 0) return;

  // Set viewing transformation
  glMatrixMode(GL_PROJECTION);  
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0, GLUTwindow_width, 0, GLUTwindow_height, 0, 1);
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  // Enable texture
  glBindTexture(GL_TEXTURE_2D, data->texture_id);
  glEnable(GL_TEXTURE_2D);

  // Draw textured polygon
  RNLoadRgb(1, 1, 1);
  RNGrfxBegin(RN_GRFX_POLYGON);
  R3LoadTextureCoords(0, 0);
  R3LoadPoint(x, y, -0.5);
  R3LoadTextureCoords(1, 0);
  R3LoadPoint(x+w, y, -0.5);
  R3LoadTextureCoords(1, 1);
  R3LoadPoint(x+w, y+h, -0.5);
  R3LoadTextureCoords(0, 1);
  R3LoadPoint(x, y+h, -0.5);
  RNGrfxEnd();

  // Disable texture
  glDisable(GL_TEXTURE_2D);

  // Restore viewing transformation
  glMatrixMode(GL_PROJECTION);  
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);  
  glPopMatrix();
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm1, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
cmpl $0x0, 0x2ca22a(%rip)    # 0x2feeec
jne 0x34cc9
jmp 0x34ea4
movsd 0x18(%rsp), %xmm0
movq 0x30(%rsp), %rax
cvtsi2sdl 0x768(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movq 0x30(%rsp), %rax
cvtsi2sdl 0x76c(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x34d16
jp 0x34d16
jmp 0x34d27
movsd 0x8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x34d2c
jp 0x34d2c
jmp 0x34ea4
movq 0x30(%rsp), %rdi
callq 0x36360
movq 0x30(%rsp), %rax
cmpl $0x0, 0x770(%rax)
jne 0x34d49
jmp 0x34ea4
movl $0x1701, %edi           # imm = 0x1701
callq 0x29190
callq 0x29d20
callq 0x294f0
cvtsi2sdl 0x2bad8b(%rip), %xmm1 # 0x2efaf0
cvtsi2sdl 0x2bad87(%rip), %xmm3 # 0x2efaf4
xorps %xmm4, %xmm4
movsd 0x231298(%rip), %xmm5   # 0x266010
movaps %xmm4, %xmm0
movaps %xmm4, %xmm2
callq 0x295d0
movl $0x1700, %edi           # imm = 0x1700
callq 0x29190
callq 0x29d20
callq 0x294f0
movq 0x30(%rsp), %rax
movl 0x770(%rax), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x2a4b0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x29a50
movl $0x1, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x39820
movl $0x9, %edi
callq 0x38d90
xorl %esi, %esi
movl %esi, %edi
callq 0x39cc0
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x2312ed(%rip), %xmm2   # 0x2660d8
callq 0x39ce0
movl $0x1, %edi
xorl %esi, %esi
callq 0x39cc0
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x2312c2(%rip), %xmm2   # 0x2660d8
callq 0x39ce0
movl $0x1, %esi
movl %esi, %edi
callq 0x39cc0
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
movsd 0x231291(%rip), %xmm2   # 0x2660d8
callq 0x39ce0
xorl %edi, %edi
movl $0x1, %esi
callq 0x39cc0
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
movsd 0x231266(%rip), %xmm2   # 0x2660d8
callq 0x39ce0
callq 0x38e40
movl $0xde1, %edi            # imm = 0xDE1
callq 0x2a130
movl $0x1701, %edi           # imm = 0x1701
callq 0x29190
callq 0x2a210
movl $0x1700, %edi           # imm = 0x1700
callq 0x29190
callq 0x2a210
addq $0x38, %rsp
retq
nopl (%rax)