#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 */

/* Variables and functions */
int /*<<< orphan*/ GL_QUAD_STRIP;
double cos(double);
int /*<<< orphan*/ glBegin(int /*<<< orphan*/);
int /*<<< orphan*/ glColor3d(double, double, double);
int /*<<< orphan*/ glEnd();
int /*<<< orphan*/ glVertex3d(double, double, double);
double sin(double);
void half_sphere(double r, int m, int n) {
  double step1 = 3.1415926 / (n + 1);
  double step2 = 3.1415926 / (m + 1);
  double t, theta = 0, phi = 0;
  int i1 = 0, i2 = 0;
  double x1, y1, z1;
  double x2, y2, z2;
  double x3, y3;
  double x4, y4;
  glBegin(GL_QUAD_STRIP);
  for (theta = 0; theta < 3.1415926 / 2; theta += step1) {
    z1 = r * cos(theta);
    z2 = r * cos(theta + step1);
    if (i1 == 0) {
      i1 = 1;
    } else {
      i1 = 0;
    }
    for (phi = 0; phi <= 2 * 3.1415926 + step2; phi += step2) {
      if (i1 == 0) {
        glColor3d(1.0, 1.0, 0.0);
        i1 = 1;
      } else {
        glColor3d(1.0, 0.2, 1.0);
        i1 = 0;
      }
      x1 = r * cos(phi) * sin(theta);
      y1 = r * sin(theta) * sin(phi);
      x2 = r * cos(phi) * sin(theta + step1);
      y2 = r * sin(theta + step1) * sin(phi);
      glVertex3d(x1, y1, z1);
      glVertex3d(x2, y2, z2);
    }
  }
  glEnd();
}


x86 assembly (clang, -O0):
<half_sphere>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe78(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe5d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1080 <glBegin@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe20(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1466 <half_sphere+0x306>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    1264 <half_sphere+0x104>
movl   $0x1,-0x3c(%rbp)
jmp    126b <half_sphere+0x10b>
movl   $0x0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  0xd90(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     144d <half_sphere+0x2ed>
cmpl   $0x0,-0x3c(%rbp)
jne    12b8 <half_sphere+0x158>
movsd  0xd77(%rip),%xmm1
xorps  %xmm2,%xmm2
movaps %xmm1,%xmm0
call   1060 <glColor3d@plt>
movl   $0x1,-0x3c(%rbp)
jmp    12d7 <half_sphere+0x177>
movsd  0xd58(%rip),%xmm2
movsd  0xd58(%rip),%xmm1
movaps %xmm2,%xmm0
call   1060 <glColor3d@plt>
movl   $0x0,-0x3c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xe0(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0xe0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xd8(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xd8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xd0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xc8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0xc0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
call   1030 <glVertex3d@plt>
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
call   1030 <glVertex3d@plt>
movsd  -0x20(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1273 <half_sphere+0x113>
jmp    1452 <half_sphere+0x2f2>
movsd  -0x18(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e0 <half_sphere+0x80>
mov    $0x0,%al
call   1040 <glEnd@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<half_sphere>:
push   %rbx
sub    $0x70,%rsp
movsd  %xmm0,0x20(%rsp)
add    $0x1,%esi
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
movsd  0xe83(%rip),%xmm3
movapd %xmm3,%xmm2
add    $0x1,%edi
cvtsi2sd %edi,%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,0x50(%rsp)
divsd  %xmm1,%xmm3
movsd  %xmm3,0x40(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1080 <glBegin@plt>
movsd  0xe56(%rip),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x48(%rsp)
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
jmp    11ec <half_sphere+0x8c>
cs nopw 0x0(%rax,%rax,1)
movsd  0xe48(%rip),%xmm0
movsd  0x38(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
jbe    13c2 <half_sphere+0x262>
movsd  %xmm0,0x30(%rsp)
call   1070 <cos@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x50(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
call   1070 <cos@plt>
movapd %xmm0,%xmm1
test   %ebx,%ebx
sete   %al
movsd  0x48(%rsp),%xmm0
ucomisd 0xdfd(%rip),%xmm0
mov    $0x0,%ebx
mov    %al,%bl
jb     11d0 <half_sphere+0x70>
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x28(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x58(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    139b <half_sphere+0x23b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0xda0(%rip),%xmm0
movsd  0xd90(%rip),%xmm1
movapd %xmm0,%xmm2
call   1060 <glColor3d@plt>
xor    %ebx,%ebx
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x30(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x68(%rsp)
movsd  0x30(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x38(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x60(%rsp)
movsd  0x38(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x68(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
call   1030 <glVertex3d@plt>
movsd  0x60(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x58(%rsp),%xmm2
call   1030 <glVertex3d@plt>
movsd  0x8(%rsp),%xmm1
addsd  0x40(%rsp),%xmm1
movsd  0x48(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm1,%xmm0
jb     11d0 <half_sphere+0x70>
test   %ebx,%ebx
jne    1270 <half_sphere+0x110>
xorpd  %xmm2,%xmm2
movsd  0xc69(%rip),%xmm0
movapd %xmm0,%xmm1
call   1060 <glColor3d@plt>
mov    $0x1,%ebx
jmp    128b <half_sphere+0x12b>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
jmp    1040 <glEnd@plt>

LLVM IR (-O0):
@GL_QUAD_STRIP = global i32 0
define void @half_sphere(double %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
%26 = sitofp i32 %25 to double
%27 = fdiv double 0x400921FB4D12D84A, %26
store double %27, double* %7
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = sitofp i32 %29 to double
%31 = fdiv double 0x400921FB4D12D84A, %30
store double %31, double* %8
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
store i32 0, i32* %13
%32 = load i32, i32* @GL_QUAD_STRIP
%33 = call i32 @glBegin(i32 %32)
store double 0.000000e+00, double* %10
br label %34
34: ; preds = %111, %3
%35 = load double, double* %10
%36 = fcmp olt double %35, 0x3FF921FB4D12D84A
br i1 %36, label %37, label %115
37: ; preds = %34
%38 = load double, double* %4
%39 = load double, double* %10
%40 = call double @cos(double %39)
%41 = fmul double %38, %40
store double %41, double* %16
%42 = load double, double* %4
%43 = load double, double* %10
%44 = load double, double* %7
%45 = fadd double %43, %44
%46 = call double @cos(double %45)
%47 = fmul double %42, %46
store double %47, double* %19
%48 = load i32, i32* %12
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %37
store i32 1, i32* %12
br label %52
51: ; preds = %37
store i32 0, i32* %12
br label %52
52: ; preds = %51, %50
store double 0.000000e+00, double* %11
br label %53
53: ; preds = %106, %52
%54 = load double, double* %11
%55 = load double, double* %8
%56 = fadd double 0x401921FB4D12D84A, %55
%57 = fcmp ole double %54, %56
br i1 %57, label %58, label %110
58: ; preds = %53
%59 = load i32, i32* %12
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @glColor3d(double 1.000000e+00, double 1.000000e+00, double 0.000000e+00)
store i32 1, i32* %12
br label %65
63: ; preds = %58
%64 = call i32 @glColor3d(double 1.000000e+00, double 2.000000e-01, double 1.000000e+00)
store i32 0, i32* %12
br label %65
65: ; preds = %63, %61
%66 = load double, double* %4
%67 = load double, double* %11
%68 = call double @cos(double %67)
%69 = fmul double %66, %68
%70 = load double, double* %10
%71 = call double @sin(double %70)
%72 = fmul double %69, %71
store double %72, double* %14
%73 = load double, double* %4
%74 = load double, double* %10
%75 = call double @sin(double %74)
%76 = fmul double %73, %75
%77 = load double, double* %11
%78 = call double @sin(double %77)
%79 = fmul double %76, %78
store double %79, double* %15
%80 = load double, double* %4
%81 = load double, double* %11
%82 = call double @cos(double %81)
%83 = fmul double %80, %82
%84 = load double, double* %10
%85 = load double, double* %7
%86 = fadd double %84, %85
%87 = call double @sin(double %86)
%88 = fmul double %83, %87
store double %88, double* %17
%89 = load double, double* %4
%90 = load double, double* %10
%91 = load double, double* %7
%92 = fadd double %90, %91
%93 = call double @sin(double %92)
%94 = fmul double %89, %93
%95 = load double, double* %11
%96 = call double @sin(double %95)
%97 = fmul double %94, %96
store double %97, double* %18
%98 = load double, double* %14
%99 = load double, double* %15
%100 = load double, double* %16
%101 = call i32 @glVertex3d(double %98, double %99, double %100)
%102 = load double, double* %17
%103 = load double, double* %18
%104 = load double, double* %19
%105 = call i32 @glVertex3d(double %102, double %103, double %104)
br label %106
106: ; preds = %65
%107 = load double, double* %8
%108 = load double, double* %11
%109 = fadd double %108, %107
store double %109, double* %11
br label %53
110: ; preds = %53
br label %111
111: ; preds = %110
%112 = load double, double* %7
%113 = load double, double* %10
%114 = fadd double %113, %112
store double %114, double* %10
br label %34
115: ; preds = %34
%116 = call i32 (...) @glEnd()
ret void
}

LLVM IR (-O2):
@GL_QUAD_STRIP = global i32 0
define void @half_sphere(double %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = sitofp i32 %4 to double
%6 = fdiv double 0x400921FB4D12D84A, %5
%7 = add nsw i32 %1, 1
%8 = sitofp i32 %7 to double
%9 = fdiv double 0x400921FB4D12D84A, %8
%10 = load i32, i32* @GL_QUAD_STRIP
%11 = tail call i32 @glBegin(i32 %10)
%12 = fadd double %9, 0x401921FB4D12D84A
%13 = fcmp ult double %12, 0.000000e+00
br label %17
14: ; preds = %35, %17
%15 = phi i32 [ %26, %17 ], [ %36, %35 ]
%16 = fcmp olt double %22, 0x3FF921FB4D12D84A
br i1 %16, label %17, label %57
17: ; preds = %3, %14
%18 = phi double [ 0.000000e+00, %3 ], [ %22, %14 ]
%19 = phi i32 [ 0, %3 ], [ %15, %14 ]
%20 = tail call double @cos(double %18)
%21 = fmul double %20, %0
%22 = fadd double %6, %18
%23 = tail call double @cos(double %22)
%24 = fmul double %23, %0
%25 = icmp eq i32 %19, 0
%26 = zext i1 %25 to i32
br i1 %13, label %14, label %27
27: ; preds = %17, %35
%28 = phi double [ %55, %35 ], [ 0.000000e+00, %17 ]
%29 = phi i32 [ %36, %35 ], [ %26, %17 ]
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @glColor3d(double 1.000000e+00, double 1.000000e+00, double 0.000000e+00)
br label %35
33: ; preds = %27
%34 = tail call i32 @glColor3d(double 1.000000e+00, double 2.000000e-01, double 1.000000e+00)
br label %35
35: ; preds = %33, %31
%36 = phi i32 [ 1, %31 ], [ 0, %33 ]
%37 = tail call double @cos(double %28)
%38 = fmul double %37, %0
%39 = tail call double @sin(double %18)
%40 = fmul double %38, %39
%41 = tail call double @sin(double %18)
%42 = fmul double %41, %0
%43 = tail call double @sin(double %28)
%44 = fmul double %42, %43
%45 = tail call double @cos(double %28)
%46 = fmul double %45, %0
%47 = tail call double @sin(double %22)
%48 = fmul double %46, %47
%49 = tail call double @sin(double %22)
%50 = fmul double %49, %0
%51 = tail call double @sin(double %28)
%52 = fmul double %50, %51
%53 = tail call i32 @glVertex3d(double %40, double %44, double %21)
%54 = tail call i32 @glVertex3d(double %48, double %52, double %24)
%55 = fadd double %9, %28
%56 = fcmp ugt double %55, %12
br i1 %56, label %14, label %27
57: ; preds = %14
%58 = tail call i32 (...) @glEnd()
ret void
}