#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*/ printf(char *, int, ...);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok_r(char *, char *, char **);
char getAll(char ref, char *alt, int x) {
  char alt1[20];
  char *s, *sps;
  unsigned int i;
  strcpy(alt1, alt);
  if (x < 0) {
    printf("\nERROR: getAll: negative position detected: %d\n", x);
    return 'n';
  } else {
    if (x == 0) {
      return ref;
    } else {
      if (x == 1) {
        return alt1[0];
      } else {
        s = strtok_r(alt1, ",", &sps);
        if (s == NULL) {
          printf("\nERROR: getAll: impossible to take the %dth allele from "
                 "alt: %s, only one present.\n",
                 x, alt1);
          return 'n';
        }
        i = 2;
        while (i == x) {
          s = strtok_r(NULL, ",", &sps);
          if ((s == NULL) && (i < x)) {
            printf("\nERROR: getAll: impossible to take the %dth allele from "
                   "alt: %s, position out of bounds.\n",
                   x, alt1);
            return 'n';
          }
          if (i == x) {
            return s[0];
          }
          i++;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<getAll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1176 <getAll+0x46>
mov    -0x14(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x6e,-0x1(%rbp)
jmp    1278 <getAll+0x148>
cmpl   $0x0,-0x14(%rbp)
jne    118b <getAll+0x5b>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1278 <getAll+0x148>
cmpl   $0x1,-0x14(%rbp)
jne    11a0 <getAll+0x70>
mov    -0x30(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1278 <getAll+0x148>
lea    -0x30(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e1 <getAll+0xb1>
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x6e,-0x1(%rbp)
jmp    1278 <getAll+0x148>
movl   $0x2,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1269 <getAll+0x139>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe31(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1241 <getAll+0x111>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1241 <getAll+0x111>
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x6e,-0x1(%rbp)
jmp    1278 <getAll+0x148>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    125b <getAll+0x12b>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    1278 <getAll+0x148>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e8 <getAll+0xb8>
jmp    126e <getAll+0x13e>
jmp    1273 <getAll+0x143>
jmp    1278 <getAll+0x148>
movsbl -0x1(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAll>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
test   %ebx,%ebx
js     1156 <getAll+0x26>
je     1169 <getAll+0x39>
cmp    $0x1,%ebx
jne    1172 <getAll+0x42>
mov    0x10(%rsp),%bpl
jmp    1169 <getAll+0x39>
lea    0xea3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x6e,%bpl
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeb7(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11aa <getAll+0x7a>
cmp    $0x2,%ebx
jne    1169 <getAll+0x39>
lea    0xe97(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1050 <strtok_r@plt>
mov    (%rax),%bpl
jmp    1169 <getAll+0x39>
lea    0xe81(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1166 <getAll+0x36>

LLVM IR (-O0):
@.str = [48 x i8] c"\0AERROR: getAll: negative position detected: %d\0A\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [84 x i8] c"\0AERROR: getAll: impossible to take the %dth allele from alt: %s, only one present.\0A\00"
@.str.3 = [90 x i8] c"\0AERROR: getAll: impossible to take the %dth allele from alt: %s, position out of bounds.\0A\00"
define signext i8 @getAll(i8 signext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8 %0, i8* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %6
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %7
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %18)
store i8 110, i8* %4
br label %71
20: ; preds = %3
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i8, i8* %5
store i8 %24, i8* %4
br label %71
25: ; preds = %20
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%30 = load i8, i8* %29
store i8 %30, i8* %4
br label %71
31: ; preds = %25
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%33 = call i8* @strtok_r(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* %7
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* %38)
store i8 110, i8* %4
br label %71
40: ; preds = %31
store i32 2, i32* %11
br label %41
41: ; preds = %65, %40
%42 = load i32, i32* %11
%43 = load i32, i32* %7
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %68
45: ; preds = %41
%46 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10)
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load i32, i32* %11
%51 = load i32, i32* %7
%52 = icmp ult i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* %7
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0), i32 %54, i8* %55)
store i8 110, i8* %4
br label %71
57: ; preds = %49, %45
%58 = load i32, i32* %11
%59 = load i32, i32* %7
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i8*, i8** %9
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
store i8 %64, i8* %4
br label %71
65: ; preds = %57
%66 = load i32, i32* %11
%67 = add i32 %66, 1
store i32 %67, i32* %11
br label %41
68: ; preds = %41
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69
br label %71
71: ; preds = %17, %23, %28, %36, %53, %61, %70
%72 = load i8, i8* %4
ret i8 %72
}

LLVM IR (-O2):
@.str = [48 x i8] c"\0AERROR: getAll: negative position detected: %d\0A\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [84 x i8] c"\0AERROR: getAll: impossible to take the %dth allele from alt: %s, only one present.\0A\00"
define signext i8 @getAll(i8 signext %0, i8* %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
%8 = call i32 @strcpy(i8* %6, i8* %1)
%9 = icmp slt i32 %2, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %25
12: ; preds = %3
switch i32 %2, label %15 [
i32 0, label %25
i32 1, label %13
]
13: ; preds = %12
%14 = load i8, i8* %6
br label %25
15: ; preds = %12
%16 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i32 %2, i8* %6)
br label %25
20: ; preds = %15
%21 = icmp eq i32 %2, 2
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%24 = load i8, i8* %23
br label %25
25: ; preds = %20, %12, %22, %18, %13, %10
%26 = phi i8 [ 110, %10 ], [ %14, %13 ], [ 110, %18 ], [ %24, %22 ], [ %0, %12 ], [ undef, %20 ]
ret i8 %26
}