#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 */
scalar_t__ strlen(char *);
char *FindAddressByIndex(unsigned int aIndex, char *aAddresses) {
  unsigned int lCurrentIndex = 0;
  unsigned int lConnectionFoundIndex = 0;
  while (strlen(aAddresses + lCurrentIndex) > 0) {
    if ((lConnectionFoundIndex / 2) == aIndex) {
      return aAddresses + lCurrentIndex;
    }
    lConnectionFoundIndex++;
    lCurrentIndex += strlen(aAddresses + lCurrentIndex) + 1;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<FindAddressByIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    1195 <FindAddressByIndex+0x85>
mov    -0x20(%rbp),%eax
shr    $0x1,%eax
cmp    -0xc(%rbp),%eax
jne    1168 <FindAddressByIndex+0x58>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    119d <FindAddressByIndex+0x8d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x1c(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
jmp    112d <FindAddressByIndex+0x1d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindAddressByIndex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    1164 <FindAddressByIndex+0x54>
test   %r14d,%r14d
je     1169 <FindAddressByIndex+0x59>
mov    $0x1,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    %eax,%ebx
add    $0x1,%ebx
lea    (%r15,%rbx,1),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    1164 <FindAddressByIndex+0x54>
mov    %ebp,%ecx
shr    %ecx
add    $0x1,%ebp
cmp    %r14d,%ecx
jne    1140 <FindAddressByIndex+0x30>
jmp    116c <FindAddressByIndex+0x5c>
xor    %r12d,%r12d
jmp    116c <FindAddressByIndex+0x5c>
mov    %r15,%r12
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @FindAddressByIndex(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %25, %2
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = call i64 @strlen(i8* %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %8
%16 = load i32, i32* %7
%17 = udiv i32 %16, 2
%18 = load i32, i32* %4
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8* %24, i8** %3
br label %39
25: ; preds = %15
%26 = load i32, i32* %7
%27 = add i32 %26, 1
store i32 %27, i32* %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = load i32, i32* %6
%35 = zext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %6
br label %8
38: ; preds = %8
store i8* null, i8** %3
br label %39
39: ; preds = %38, %20
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
define i8* @FindAddressByIndex(i32 %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = icmp eq i32 %0, 0
br i1 %6, label %21, label %10
7: ; preds = %10
%8 = lshr i32 %14, 1
%9 = icmp eq i32 %8, %0
br i1 %9, label %21, label %10
10: ; preds = %5, %7
%11 = phi i32 [ %14, %7 ], [ 0, %5 ]
%12 = phi i64 [ %17, %7 ], [ 0, %5 ]
%13 = phi i64 [ %19, %7 ], [ %3, %5 ]
%14 = add i32 %11, 1
%15 = add nuw nsw i64 %12, 1
%16 = add i64 %15, %13
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %7, label %21
21: ; preds = %10, %7, %5, %2
%22 = phi i8* [ null, %2 ], [ %1, %5 ], [ %18, %7 ], [ null, %10 ]
ret i8* %22
}