#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 */
struct Xorriso_lsT {
  int dummy;
};
struct XorrisO {
  int dummy;
};

/* Variables and functions */
struct Xorriso_lsT *Xorriso_lst_get_next(struct Xorriso_lsT *,
                                         int /*<<< orphan*/);
char *Xorriso_lst_get_text(struct Xorriso_lsT *, int /*<<< orphan*/);
char *Xorriso_get_pattern(struct XorrisO *xorriso,
                          struct Xorriso_lsT *patternlist, int index,
                          int flag) {
  int i = 0;
  struct Xorriso_lsT *s;
  for (s = patternlist; s != NULL; s = Xorriso_lst_get_next(s, 0)) {
    if (i == index)
      return (Xorriso_lst_get_text(s, 0));
    i++;
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<Xorriso_get_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     118d <Xorriso_get_pattern+0x6d>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1170 <Xorriso_get_pattern+0x50>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1030 <Xorriso_lst_get_text@plt>
mov    %rax,-0x8(%rbp)
jmp    1195 <Xorriso_get_pattern+0x75>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1040 <Xorriso_lst_get_next@plt>
mov    %rax,-0x30(%rbp)
jmp    1145 <Xorriso_get_pattern+0x25>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Xorriso_get_pattern>:
push   %rbx
test   %rsi,%rsi
je     1144 <Xorriso_get_pattern+0x24>
mov    %edx,%ebx
mov    %rsi,%rax
add    $0x1,%ebx
xchg   %ax,%ax
mov    %rax,%rdi
xor    %esi,%esi
add    $0xffffffff,%ebx
je     1148 <Xorriso_get_pattern+0x28>
call   1040 <Xorriso_lst_get_next@plt>
test   %rax,%rax
jne    1130 <Xorriso_get_pattern+0x10>
xor    %eax,%eax
pop    %rbx
ret
pop    %rbx
jmp    1030 <Xorriso_lst_get_text@plt>

LLVM IR (-O0):
%struct.XorrisO = type { i32 }
%struct.Xorriso_lsT = type { i32 }
define i8* @Xorriso_get_pattern(%struct.XorrisO* %0, %struct.Xorriso_lsT* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca %struct.XorrisO*
%7 = alloca %struct.Xorriso_lsT*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.Xorriso_lsT*
store %struct.XorrisO* %0, %struct.XorrisO** %6
store %struct.Xorriso_lsT* %1, %struct.Xorriso_lsT** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
%12 = load %struct.Xorriso_lsT*, %struct.Xorriso_lsT** %7
store %struct.Xorriso_lsT* %12, %struct.Xorriso_lsT** %11
br label %13
13: ; preds = %26, %4
%14 = load %struct.Xorriso_lsT*, %struct.Xorriso_lsT** %11
%15 = icmp ne %struct.Xorriso_lsT* %14, null
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32, i32* %10
%18 = load i32, i32* %8
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load %struct.Xorriso_lsT*, %struct.Xorriso_lsT** %11
%22 = call i8* @Xorriso_lst_get_text(%struct.Xorriso_lsT* %21, i32 0)
store i8* %22, i8** %5
br label %30
23: ; preds = %16
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
store i32 %25, i32* %10
br label %26
26: ; preds = %23
%27 = load %struct.Xorriso_lsT*, %struct.Xorriso_lsT** %11
%28 = call %struct.Xorriso_lsT* @Xorriso_lst_get_next(%struct.Xorriso_lsT* %27, i32 0)
store %struct.Xorriso_lsT* %28, %struct.Xorriso_lsT** %11
br label %13
29: ; preds = %13
store i8* null, i8** %5
br label %30
30: ; preds = %29, %20
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
%struct.XorrisO = type { i32 }
%struct.Xorriso_lsT = type { i32 }
define i8* @Xorriso_get_pattern(%struct.XorrisO* nocapture readnone %0, %struct.Xorriso_lsT* %1, i32 %2, i32 %3) {
%5 = icmp eq %struct.Xorriso_lsT* %1, null
br i1 %5, label %16, label %6
6: ; preds = %4, %12
%7 = phi %struct.Xorriso_lsT* [ %14, %12 ], [ %1, %4 ]
%8 = phi i32 [ %13, %12 ], [ 0, %4 ]
%9 = icmp eq i32 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i8* @Xorriso_lst_get_text(%struct.Xorriso_lsT* %7, i32 0)
br label %16
12: ; preds = %6
%13 = add nuw nsw i32 %8, 1
%14 = tail call %struct.Xorriso_lsT* @Xorriso_lst_get_next(%struct.Xorriso_lsT* %7, i32 0)
%15 = icmp eq %struct.Xorriso_lsT* %14, null
br i1 %15, label %16, label %6
16: ; preds = %12, %4, %10
%17 = phi i8* [ %11, %10 ], [ null, %4 ], [ null, %12 ]
ret i8* %17
}