#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*/ printf(char *, ...);
void print_activities(int start[], int finish[], int n) {
  printf("%s", "Following activities are selected");
  int i = 0;
  printf("\n%d  ", i);
  for (int j = 1; j < n; j++) {
    if (start[j] >= finish[i]) {
      printf("%d  ", j);
      i = j;
    }
  }
}


x86 assembly (clang, -O0):
<print_activities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xed6(%rip),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a9 <print_activities+0x99>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jl     1196 <print_activities+0x86>
mov    -0x1c(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    119b <print_activities+0x8b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <print_activities+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_activities>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xed8(%rip),%rdi
lea    0xed4(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebx
jl     1186 <print_activities+0x76>
mov    %ebx,%r13d
mov    $0x1,%ebx
lea    0xecc(%rip),%r12
xor    %eax,%eax
jmp    1169 <print_activities+0x59>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r13
je     1186 <print_activities+0x76>
mov    (%r15,%rbx,4),%ecx
movslq %eax,%rdx
cmp    (%r14,%rdx,4),%ecx
jl     1160 <print_activities+0x50>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
jmp    1160 <print_activities+0x50>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [34 x i8] c"Following activities are selected\00"
@.str.2 = [6 x i8] c"\0A%d \00"
@.str.3 = [5 x i8] c"%d \00"
define void @print_activities(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
%10 = load i32, i32* %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %10)
store i32 1, i32* %8
br label %12
12: ; preds = %33, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp sge i32 %21, %26
br i1 %27, label %28, label %32
28: ; preds = %16
%29 = load i32, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %8
store i32 %31, i32* %7
br label %32
32: ; preds = %28, %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %12
36: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [34 x i8] c"Following activities are selected\00"
@.str.2 = [6 x i8] c"\0A%d \00"
@.str.3 = [5 x i8] c"%d \00"
define void @print_activities(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0)
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %10
9: ; preds = %22, %3
ret void
10: ; preds = %7, %22
%11 = phi i64 [ 1, %7 ], [ %24, %22 ]
%12 = phi i32 [ 0, %7 ], [ %23, %22 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %11
%14 = load i32, i32* %13
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = icmp slt i32 %14, %17
br i1 %18, label %22, label %19
19: ; preds = %10
%20 = trunc i64 %11 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %10, %19
%23 = phi i32 [ %20, %19 ], [ %12, %10 ]
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %9, label %10
}