#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 strlen(char *);
int *gChar(char *str, char c) {
  int i = 0;
  int i1 = 0;
  int ret[1024];
  while (i < strlen(str)) {
    if (str[i] == c) {
      ret[i1] = i;
      i1++;
    }
    i++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<gChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1024(%rbp),%eax
cmp    %ecx,%eax
jge    1192 <gChar+0x82>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1184 <gChar+0x74>
mov    -0x10(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x1020(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1133 <gChar+0x23>
lea    -0x1020(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gChar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1164 <gChar+0x54>
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1153 <gChar+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1164 <gChar+0x54>
cmp    %r14b,(%r15,%rbp,1)
jne    1140 <gChar+0x30>
movslq %ebx,%rbx
mov    %ebp,(%rsp,%rbx,4)
add    $0x1,%ebx
jmp    1140 <gChar+0x30>
mov    %rsp,%rax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @gChar(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i32]
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %30, %2
%9 = load i32, i32* %5
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %33
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %30
23: ; preds = %13
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %26
store i32 %24, i32* %27
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %30
30: ; preds = %23, %13
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %8
33: ; preds = %8
%34 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
ret i32* %34
}

LLVM IR (-O2):
define noalias i32* @gChar(i8* %0, i8 signext %1) {
%3 = alloca [1024 x i32]
%4 = bitcast [1024 x i32]* %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %2, %18
%8 = phi i64 [ %20, %18 ], [ 0, %2 ]
%9 = phi i32 [ %19, %18 ], [ 0, %2 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, %1
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 %14
%16 = trunc i64 %8 to i32
store i32 %16, i32* %15
%17 = add nsw i32 %9, 1
br label %18
18: ; preds = %13, %7
%19 = phi i32 [ %17, %13 ], [ %9, %7 ]
%20 = add nuw nsw i64 %8, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %7, label %24
24: ; preds = %18, %2
%25 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
ret i32* %25
}