#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*/ free(size_t *);
int /*<<< orphan*/ printf(char *, size_t, ...);
size_t *strutil_indices_of(char *, char, size_t *);
int main(void) {
  size_t amount = 0;
  char l = 'l';
  char *str = "Hello, world!";
  size_t *indices = strutil_indices_of(str, l, &amount);
  printf("Indices of '%c' in \"%s\"\n", l, str);
  for (size_t i = 0; i < amount; i++) {
    if (i < amount - 1) {
      printf("%lu, ", indices[i]);
    } else {
      printf("%lu\n", indices[i]);
    }
  }
  free(indices);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movb   $0x6c,-0x11(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rdx
movsbl -0x11(%rbp),%esi
call   1050 <strutil_indices_of@plt>
mov    %rax,-0x28(%rbp)
movsbq -0x11(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11fc <main+0xcc>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11cc <main+0x9c>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e6 <main+0xb6>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <main+0xbb>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    118a <main+0x5a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
lea    0xeb9(%rip),%r14
mov    %rsp,%rdx
mov    %r14,%rdi
mov    $0x6c,%esi
call   1050 <strutil_indices_of@plt>
mov    %rax,%r12
lea    0xead(%rip),%rdi
mov    $0x6c,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rax
test   %rax,%rax
je     11b6 <main+0x86>
lea    0xea7(%rip),%r14
lea    0xea6(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
cmovb  %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    (%rsp),%rax
cmp    %rax,%rbx
jb     1190 <main+0x60>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [25 x i8] c"Indices of '%c' in \22%s\22\0A\00"
@.str.2 = [6 x i8] c"%lu, \00"
@.str.3 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %2
store i8 108, i8* %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = load i8*, i8** %4
%8 = load i8, i8* %3
%9 = call i64* @strutil_indices_of(i8* %7, i8 signext %8, i64* %2)
store i64* %9, i64** %5
%10 = load i8, i8* %3
%11 = sext i8 %10 to i64
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %11, i8* %12)
store i64 0, i64* %6
br label %14
14: ; preds = %36, %0
%15 = load i64, i64* %6
%16 = load i64, i64* %2
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i64, i64* %6
%20 = load i64, i64* %2
%21 = sub i64 %20, 1
%22 = icmp ult i64 %19, %21
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i64*, i64** %5
%25 = load i64, i64* %6
%26 = getelementptr inbounds i64, i64* %24, i64 %25
%27 = load i64, i64* %26
%28 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %35
29: ; preds = %18
%30 = load i64*, i64** %5
%31 = load i64, i64* %6
%32 = getelementptr inbounds i64, i64* %30, i64 %31
%33 = load i64, i64* %32
%34 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %29, %23
br label %36
36: ; preds = %35
%37 = load i64, i64* %6
%38 = add i64 %37, 1
store i64 %38, i64* %6
br label %14
39: ; preds = %14
%40 = load i64*, i64** %5
%41 = call i32 @free(i64* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [25 x i8] c"Indices of '%c' in \22%s\22\0A\00"
@.str.2 = [6 x i8] c"%lu, \00"
@.str.3 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%3 = call i64* @strutil_indices_of(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext 108, i64* %1)
%4 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 108, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %9, %0
%8 = call i32 @free(i64* %3)
ret i32 0
9: ; preds = %0, %9
%10 = phi i64 [ %19, %9 ], [ %5, %0 ]
%11 = phi i64 [ %18, %9 ], [ 0, %0 ]
%12 = add i64 %10, -1
%13 = icmp ult i64 %11, %12
%14 = getelementptr inbounds i64, i64* %3, i64 %11
%15 = load i64, i64* %14
%16 = select i1 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%17 = call i32 (i8*, i64, ...) @printf(i8* %16, i64 %15)
%18 = add nuw i64 %11, 1
%19 = load i64, i64* %1
%20 = icmp ult i64 %18, %19
br i1 %20, label %9, label %7
}