#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 courseintb {
  int dummy;
};

/* Variables and functions */
scalar_t__ distancecost(int, int);
int lookforcourse(int, struct courseintb **, int);
double costforstudent(int *student, struct courseintb **timetable,
                      int timeslots) {
  double studentcost = 0.0;
  int temp = 0, temp2 = 0, distance = 0, distance2 = 0, i = 0, j = 0;
  while (student[i] != 0) {
    temp = student[i];
    j = i;
    while (student[j + 1] != 0) {
      temp2 = student[j + 1];
      distance = lookforcourse(temp, timetable, timeslots);
      distance2 = lookforcourse(temp2, timetable, timeslots);
      studentcost += distancecost(distance, distance2);
      j++;
    }
    i++;
  }
  return studentcost;
}


x86 assembly (clang, -O0):
<costforstudent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     120f <costforstudent+0xef>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1201 <costforstudent+0xe1>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <lookforcourse@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <lookforcourse@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1040 <distancecost@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118b <costforstudent+0x6b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1165 <costforstudent+0x45>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<costforstudent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    (%rdi),%r15d
test   %r15d,%r15d
je     11e7 <costforstudent+0xc7>
mov    %edx,%r12d
mov    %rsi,%r13
lea    0x8(%rdi),%r14
xorps  %xmm0,%xmm0
xor    %eax,%eax
mov    %rdi,0x10(%rsp)
xchg   %ax,%ax
mov    0x4(%rdi,%rax,4),%ebp
test   %ebp,%ebp
je     11ea <costforstudent+0xca>
add    $0x1,%rax
mov    %rax,0x18(%rsp)
mov    %r14,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <lookforcourse@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <lookforcourse@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <distancecost@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mov    (%r14),%ebp
add    $0x4,%r14
test   %ebp,%ebp
jne    1170 <costforstudent+0x50>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rax
mov    (%rdi,%rax,4),%r15d
mov    0x20(%rsp),%r14
add    $0x4,%r14
test   %r15d,%r15d
jne    1150 <costforstudent+0x30>
jmp    11ea <costforstudent+0xca>
xorps  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.courseintb = type { i32 }
define double @costforstudent(i32* %0, %struct.courseintb** %1, i32 %2) {
%4 = alloca i32*
%5 = alloca %struct.courseintb**
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store %struct.courseintb** %1, %struct.courseintb*** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %59, %3
%15 = load i32*, i32** %4
%16 = load i32, i32* %12
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %62
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
store i32 %26, i32* %8
%27 = load i32, i32* %12
store i32 %27, i32* %13
br label %28
28: ; preds = %36, %21
%29 = load i32*, i32** %4
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %59
36: ; preds = %28
%37 = load i32*, i32** %4
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = load i32, i32* %41
store i32 %42, i32* %9
%43 = load i32, i32* %8
%44 = load %struct.courseintb**, %struct.courseintb*** %5
%45 = load i32, i32* %6
%46 = call i32 @lookforcourse(i32 %43, %struct.courseintb** %44, i32 %45)
store i32 %46, i32* %10
%47 = load i32, i32* %9
%48 = load %struct.courseintb**, %struct.courseintb*** %5
%49 = load i32, i32* %6
%50 = call i32 @lookforcourse(i32 %47, %struct.courseintb** %48, i32 %49)
store i32 %50, i32* %11
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = call i64 @distancecost(i32 %51, i32 %52)
%54 = sitofp i64 %53 to double
%55 = load double, double* %7
%56 = fadd double %55, %54
store double %56, double* %7
%57 = load i32, i32* %13
%58 = add nsw i32 %57, 1
store i32 %58, i32* %13
br label %28
59: ; preds = %28
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %14
62: ; preds = %14
%63 = load double, double* %7
ret double %63
}

LLVM IR (-O2):
%struct.courseintb = type { i32 }
define double @costforstudent(i32* nocapture %0, %struct.courseintb** %1, i32 %2) {
%4 = load i32, i32* %0
%5 = icmp eq i32 %4, 0
br i1 %5, label %32, label %6
6: ; preds = %3, %28
%7 = phi i64 [ %11, %28 ], [ 0, %3 ]
%8 = phi i64 [ %31, %28 ], [ 1, %3 ]
%9 = phi i32 [ %29, %28 ], [ %4, %3 ]
%10 = phi double [ %23, %28 ], [ 0.000000e+00, %3 ]
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %6, %15
%16 = phi i64 [ %24, %15 ], [ %8, %6 ]
%17 = phi i32 [ %26, %15 ], [ %13, %6 ]
%18 = phi double [ %23, %15 ], [ %10, %6 ]
%19 = tail call i32 @lookforcourse(i32 %9, %struct.courseintb** %1, i32 %2)
%20 = tail call i32 @lookforcourse(i32 %17, %struct.courseintb** %1, i32 %2)
%21 = tail call i64 @distancecost(i32 %19, i32 %20)
%22 = sitofp i64 %21 to double
%23 = fadd double %18, %22
%24 = add nuw i64 %16, 1
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %15
%29 = load i32, i32* %12
%30 = icmp eq i32 %29, 0
%31 = add nuw i64 %8, 1
br i1 %30, label %32, label %6
32: ; preds = %6, %28, %3
%33 = phi double [ 0.000000e+00, %3 ], [ %10, %6 ], [ %23, %28 ]
ret double %33
}