#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*/ glEnd();
int /*<<< orphan*/ glVertex3f(double, double, double);
double sin(double);
void torus(int numc, int numt) {
  int i, j, k;
  double s, t, x, y, z, twopi;
  twopi = 2 * (double)3.14159265358979323846;
  for (i = 0; i < numc; i++) {
    glBegin(GL_QUAD_STRIP);
    for (j = 0; j <= numt; j++) {
      for (k = 1; k >= 0; k--) {
        s = (i + k) % numc + 0.5;
        t = j % numt;
        x = (1 + .1 * cos(s * twopi / numc)) * cos(t * twopi / numt);
        y = (1 + .1 * cos(s * twopi / numc)) * sin(t * twopi / numt);
        z = .1 * sin(s * twopi / numc);
        glVertex3f(x, y, z);
      }
    }
    glEnd();
  }
}


x86 assembly (clang, -O0):
<torus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  0xe9a(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1311 <torus+0x1c1>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1070 <glBegin@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12fc <torus+0x1ac>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     12e9 <torus+0x199>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
cltd
idivl  -0x4(%rbp)
cvtsi2sd %edx,%xmm0
movsd  0xe52(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <cos@plt>
movsd  0xe09(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe05(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <cos@plt>
movsd  0xdab(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xda7(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xd4a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
call   1030 <glVertex3f@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <torus+0x56>
jmp    12ee <torus+0x19e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <torus+0x43>
mov    $0x0,%al
call   1040 <glEnd@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <torus+0x22>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<torus>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
jle    13cf <torus+0x27f>
mov    %esi,%ebx
mov    %edi,%r14d
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x40(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
movsd  %xmm0,0x38(%rsp)
lea    0x1(%rbx),%ebp
xor    %r15d,%r15d
xorpd  %xmm0,%xmm0
xor    %r13d,%r13d
xorpd  %xmm1,%xmm1
jmp    11ba <torus+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <glEnd@plt>
movsd  0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
cmp    %r14d,%r13d
je     13cf <torus+0x27f>
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <glBegin@plt>
add    $0x1,%r13d
movsd  0xe20(%rip),%xmm0
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
test   %ebx,%ebx
movsd  0x38(%rsp),%xmm3
js     11a0 <torus+0x50>
xor    %r12d,%r12d
cmp    %r14d,%r13d
mov    %r13d,%eax
cmove  %r12d,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  0xdf2(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  0xdee(%rip),%xmm4
mulsd  %xmm4,%xmm2
movsd  0x40(%rsp),%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x30(%rsp)
movsd  0x10(%rsp),%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm4,%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
xchg   %ax,%ax
cmp    %r12d,%ebx
mov    %r12d,%eax
cmove  %r15d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xda7(%rip),%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x30(%rsp),%xmm0
call   1060 <cos@plt>
movapd %xmm0,%xmm1
movsd  0xd8e(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xd6a(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x30(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0xd4e(%rip),%xmm0
addsd  0xd2e(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <sin@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
call   1050 <sin@plt>
movapd %xmm0,%xmm2
mulsd  0xd0e(%rip),%xmm2
movsd  0x28(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <glVertex3f@plt>
movsd  0x10(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0xcea(%rip),%xmm0
addsd  0xcca(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0xcb2(%rip),%xmm0
addsd  0xc92(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <sin@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <sin@plt>
movapd %xmm0,%xmm2
mulsd  0xc72(%rip),%xmm2
movsd  0x28(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <glVertex3f@plt>
movsd  0x38(%rsp),%xmm3
add    $0x1,%r12d
cmp    %r12d,%ebp
jne    1250 <torus+0x100>
jmp    11a0 <torus+0x50>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GL_QUAD_STRIP = global i32 0
define void @torus(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
store double 0x401921FB54442D18, double* %13
store i32 0, i32* %5
br label %14
14: ; preds = %94, %2
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %97
18: ; preds = %14
%19 = load i32, i32* @GL_QUAD_STRIP
%20 = call i32 @glBegin(i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %89, %18
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %92
25: ; preds = %21
store i32 1, i32* %7
br label %26
26: ; preds = %85, %25
%27 = load i32, i32* %7
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %88
29: ; preds = %26
%30 = load i32, i32* %5
%31 = load i32, i32* %7
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %3
%34 = srem i32 %32, %33
%35 = sitofp i32 %34 to double
%36 = fadd double %35, 5.000000e-01
store double %36, double* %8
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = srem i32 %37, %38
%40 = sitofp i32 %39 to double
store double %40, double* %9
%41 = load double, double* %8
%42 = load double, double* %13
%43 = fmul double %41, %42
%44 = load i32, i32* %3
%45 = sitofp i32 %44 to double
%46 = fdiv double %43, %45
%47 = call double @cos(double %46)
%48 = call double @llvm.fmuladd.f64(double 1.000000e-01, double %47, double 1.000000e+00)
%49 = load double, double* %9
%50 = load double, double* %13
%51 = fmul double %49, %50
%52 = load i32, i32* %4
%53 = sitofp i32 %52 to double
%54 = fdiv double %51, %53
%55 = call double @cos(double %54)
%56 = fmul double %48, %55
store double %56, double* %10
%57 = load double, double* %8
%58 = load double, double* %13
%59 = fmul double %57, %58
%60 = load i32, i32* %3
%61 = sitofp i32 %60 to double
%62 = fdiv double %59, %61
%63 = call double @cos(double %62)
%64 = call double @llvm.fmuladd.f64(double 1.000000e-01, double %63, double 1.000000e+00)
%65 = load double, double* %9
%66 = load double, double* %13
%67 = fmul double %65, %66
%68 = load i32, i32* %4
%69 = sitofp i32 %68 to double
%70 = fdiv double %67, %69
%71 = call double @sin(double %70)
%72 = fmul double %64, %71
store double %72, double* %11
%73 = load double, double* %8
%74 = load double, double* %13
%75 = fmul double %73, %74
%76 = load i32, i32* %3
%77 = sitofp i32 %76 to double
%78 = fdiv double %75, %77
%79 = call double @sin(double %78)
%80 = fmul double 1.000000e-01, %79
store double %80, double* %12
%81 = load double, double* %10
%82 = load double, double* %11
%83 = load double, double* %12
%84 = call i32 @glVertex3f(double %81, double %82, double %83)
br label %85
85: ; preds = %29
%86 = load i32, i32* %7
%87 = add nsw i32 %86, -1
store i32 %87, i32* %7
br label %26
88: ; preds = %26
br label %89
89: ; preds = %88
%90 = load i32, i32* %6
%91 = add nsw i32 %90, 1
store i32 %91, i32* %6
br label %21
92: ; preds = %21
%93 = call i32 (...) @glEnd()
br label %94
94: ; preds = %92
%95 = load i32, i32* %5
%96 = add nsw i32 %95, 1
store i32 %96, i32* %5
br label %14
97: ; preds = %14
ret void
}

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