#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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
void greedy_activity_selector(int *s, int *f, char *a) {
  int k, n, m;
  char buf[4];
  strcat(a, "a1 ");
  n = 11;
  k = 1;
  for (m = 2; m <= n; m++) {
    if (s[m] >= f[k]) {
      sprintf(buf, "a%d ", m);
      strcat(a, buf);
      k = m;
    }
  }
}


x86 assembly (clang, -O0):
<greedy_activity_selector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1030 <strcat@plt>
movl   $0xb,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11ba <greedy_activity_selector+0x9a>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jl     11a7 <greedy_activity_selector+0x87>
lea    -0x28(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe75(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strcat@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <greedy_activity_selector+0x8c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <greedy_activity_selector+0x39>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<greedy_activity_selector>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xec8(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcat@plt>
mov    0x4(%r15),%eax
cmp    %eax,0x8(%rbx)
jge    11c6 <greedy_activity_selector+0xa6>
cmp    %eax,0xc(%rbx)
jge    11f7 <greedy_activity_selector+0xd7>
cmp    %eax,0x10(%rbx)
jge    1228 <greedy_activity_selector+0x108>
cmp    %eax,0x14(%rbx)
jge    1259 <greedy_activity_selector+0x139>
cmp    %eax,0x18(%rbx)
jge    128a <greedy_activity_selector+0x16a>
cmp    %eax,0x1c(%rbx)
jge    12bb <greedy_activity_selector+0x19b>
cmp    %eax,0x20(%rbx)
jge    12ec <greedy_activity_selector+0x1cc>
cmp    %eax,0x24(%rbx)
jge    131d <greedy_activity_selector+0x1fd>
cmp    %eax,0x28(%rbx)
jge    134e <greedy_activity_selector+0x22e>
cmp    %eax,0x2c(%rbx)
jl     11ba <greedy_activity_selector+0x9a>
lea    0xe67(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe37(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x2,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x8(%r15),%eax
cmp    %eax,0xc(%rbx)
jl     1152 <greedy_activity_selector+0x32>
lea    0xe06(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x3,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0xc(%r15),%eax
cmp    %eax,0x10(%rbx)
jl     115b <greedy_activity_selector+0x3b>
lea    0xdd5(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x4,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x10(%r15),%eax
cmp    %eax,0x14(%rbx)
jl     1164 <greedy_activity_selector+0x44>
lea    0xda4(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x5,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x14(%r15),%eax
cmp    %eax,0x18(%rbx)
jl     116d <greedy_activity_selector+0x4d>
lea    0xd73(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x6,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x18(%r15),%eax
cmp    %eax,0x1c(%rbx)
jl     1176 <greedy_activity_selector+0x56>
lea    0xd42(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x7,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x1c(%r15),%eax
cmp    %eax,0x20(%rbx)
jl     117f <greedy_activity_selector+0x5f>
lea    0xd11(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x8,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x20(%r15),%eax
cmp    %eax,0x24(%rbx)
jl     1188 <greedy_activity_selector+0x68>
lea    0xce0(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x9,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x24(%r15),%eax
cmp    %eax,0x28(%rbx)
jl     1191 <greedy_activity_selector+0x71>
lea    0xcaf(%rip),%rsi
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0xa,%edx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcat@plt>
mov    0x28(%r15),%eax
cmp    %eax,0x2c(%rbx)
jge    1196 <greedy_activity_selector+0x76>
jmp    11ba <greedy_activity_selector+0x9a>

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

LLVM IR (-O2):
@.str = [4 x i8] c"a1 \00"
@.str.1 = [5 x i8] c"a%d \00"
define void @greedy_activity_selector(i32* nocapture %0, i32* nocapture %1, i8* %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %1, i64 1
%10 = load i32, i32* %9
%11 = icmp slt i32 %8, %10
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2)
%14 = call i32 @strcat(i8* %2, i8* %5)
%15 = getelementptr inbounds i32, i32* %1, i64 2
%16 = load i32, i32* %15
br label %17
17: ; preds = %3, %12
%18 = phi i32 [ %16, %12 ], [ %10, %3 ]
%19 = getelementptr inbounds i32, i32* %0, i64 3
%20 = load i32, i32* %19
%21 = icmp slt i32 %20, %18
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%24 = call i32 @strcat(i8* %2, i8* %5)
%25 = getelementptr inbounds i32, i32* %1, i64 3
%26 = load i32, i32* %25
br label %27
27: ; preds = %22, %17
%28 = phi i32 [ %26, %22 ], [ %18, %17 ]
%29 = getelementptr inbounds i32, i32* %0, i64 4
%30 = load i32, i32* %29
%31 = icmp slt i32 %30, %28
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%34 = call i32 @strcat(i8* %2, i8* %5)
%35 = getelementptr inbounds i32, i32* %1, i64 4
%36 = load i32, i32* %35
br label %37
37: ; preds = %32, %27
%38 = phi i32 [ %36, %32 ], [ %28, %27 ]
%39 = getelementptr inbounds i32, i32* %0, i64 5
%40 = load i32, i32* %39
%41 = icmp slt i32 %40, %38
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%44 = call i32 @strcat(i8* %2, i8* %5)
%45 = getelementptr inbounds i32, i32* %1, i64 5
%46 = load i32, i32* %45
br label %47
47: ; preds = %42, %37
%48 = phi i32 [ %46, %42 ], [ %38, %37 ]
%49 = getelementptr inbounds i32, i32* %0, i64 6
%50 = load i32, i32* %49
%51 = icmp slt i32 %50, %48
br i1 %51, label %57, label %52
52: ; preds = %47
%53 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%54 = call i32 @strcat(i8* %2, i8* %5)
%55 = getelementptr inbounds i32, i32* %1, i64 6
%56 = load i32, i32* %55
br label %57
57: ; preds = %52, %47
%58 = phi i32 [ %56, %52 ], [ %48, %47 ]
%59 = getelementptr inbounds i32, i32* %0, i64 7
%60 = load i32, i32* %59
%61 = icmp slt i32 %60, %58
br i1 %61, label %67, label %62
62: ; preds = %57
%63 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 7)
%64 = call i32 @strcat(i8* %2, i8* %5)
%65 = getelementptr inbounds i32, i32* %1, i64 7
%66 = load i32, i32* %65
br label %67
67: ; preds = %62, %57
%68 = phi i32 [ %66, %62 ], [ %58, %57 ]
%69 = getelementptr inbounds i32, i32* %0, i64 8
%70 = load i32, i32* %69
%71 = icmp slt i32 %70, %68
br i1 %71, label %77, label %72
72: ; preds = %67
%73 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 8)
%74 = call i32 @strcat(i8* %2, i8* %5)
%75 = getelementptr inbounds i32, i32* %1, i64 8
%76 = load i32, i32* %75
br label %77
77: ; preds = %72, %67
%78 = phi i32 [ %76, %72 ], [ %68, %67 ]
%79 = getelementptr inbounds i32, i32* %0, i64 9
%80 = load i32, i32* %79
%81 = icmp slt i32 %80, %78
br i1 %81, label %87, label %82
82: ; preds = %77
%83 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 9)
%84 = call i32 @strcat(i8* %2, i8* %5)
%85 = getelementptr inbounds i32, i32* %1, i64 9
%86 = load i32, i32* %85
br label %87
87: ; preds = %82, %77
%88 = phi i32 [ %86, %82 ], [ %78, %77 ]
%89 = getelementptr inbounds i32, i32* %0, i64 10
%90 = load i32, i32* %89
%91 = icmp slt i32 %90, %88
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 10)
%94 = call i32 @strcat(i8* %2, i8* %5)
%95 = getelementptr inbounds i32, i32* %1, i64 10
%96 = load i32, i32* %95
br label %97
97: ; preds = %92, %87
%98 = phi i32 [ %96, %92 ], [ %88, %87 ]
%99 = getelementptr inbounds i32, i32* %0, i64 11
%100 = load i32, i32* %99
%101 = icmp slt i32 %100, %98
br i1 %101, label %105, label %102
102: ; preds = %97
%103 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 11)
%104 = call i32 @strcat(i8* %2, i8* %5)
br label %105
105: ; preds = %102, %97
ret void
}