#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 */
typedef int /*<<< orphan*/ v13;
typedef int /*<<< orphan*/ v12;
struct altera_syscons_parser {
  int dummy;
};

/* Variables and functions */
struct altera_syscons_parser *altera_get_v12_parser();
struct altera_syscons_parser *altera_get_v13_parser();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
scalar_t__ strncmp(char const *, char const *, int);
struct altera_syscons_parser *altera_choose_parser(const char *version) {
  static const char v12[] = "return {12";
  static const char v13[] = "return \"13";
  if (strncmp(version, v12, sizeof(v12) - 1) == 0)
    return altera_get_v12_parser();
  if (version[0] == '#') {
    version = strchr(version, '\n');
    if (version == NULL) {
      fprintf(stderr, "Unterminated comment:\n'%s'\n", version);
      return (NULL);
    }
    version++;
  }
  if (strncmp(version, v13, sizeof(v13) - 1) == 0)
    return altera_get_v13_parser();
  fprintf(stderr, "Unknown version string '%s'\n", version);
  return (NULL);
}


x86 assembly (clang, -O0):
<altera_choose_parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118b <altera_choose_parser+0x3b>
mov    $0x0,%al
call   1070 <altera_get_v12_parser@plt>
mov    %rax,-0x8(%rbp)
jmp    123a <altera_choose_parser+0xea>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11ea <altera_choose_parser+0x9a>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <altera_choose_parser+0x8e>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    123a <altera_choose_parser+0xea>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe16(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1219 <altera_choose_parser+0xc9>
mov    $0x0,%al
call   1060 <altera_get_v13_parser@plt>
mov    %rax,-0x8(%rbp)
jmp    123a <altera_choose_parser+0xea>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<altera_choose_parser>:
push   %rbx
mov    %rdi,%rbx
lea    0xea5(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b6 <altera_choose_parser+0x66>
cmpb   $0x23,(%rbx)
jne    1188 <altera_choose_parser+0x38>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c6 <altera_choose_parser+0x76>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11be <altera_choose_parser+0x6e>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %rbx,%rdx
jmp    11d8 <altera_choose_parser+0x88>
xor    %eax,%eax
pop    %rbx
jmp    1070 <altera_get_v12_parser@plt>
xor    %eax,%eax
pop    %rbx
jmp    1060 <altera_get_v13_parser@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
xor    %edx,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.altera_syscons_parser = type { i32 }
@altera_choose_parser.v12 = internal constant [11 x i8] c"return {12\00"
@altera_choose_parser.v13 = internal constant [11 x i8] c"return \2213\00"
@stderr = global i32 0
@.str = [28 x i8] c"Unterminated comment:\0A'%s'\0A\00"
@.str.1 = [29 x i8] c"Unknown version string '%s'\0A\00"
define %struct.altera_syscons_parser* @altera_choose_parser(i8* %0) {
%2 = alloca %struct.altera_syscons_parser*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @altera_choose_parser.v12, i64 0, i64 0), i32 10)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call %struct.altera_syscons_parser* (...) @altera_get_v12_parser()
store %struct.altera_syscons_parser* %8, %struct.altera_syscons_parser** %2
br label %37
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 35
br i1 %14, label %15, label %27
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 10)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %22)
store %struct.altera_syscons_parser* null, %struct.altera_syscons_parser** %2
br label %37
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
br label %27
27: ; preds = %24, %9
%28 = load i8*, i8** %3
%29 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @altera_choose_parser.v13, i64 0, i64 0), i32 10)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call %struct.altera_syscons_parser* (...) @altera_get_v13_parser()
store %struct.altera_syscons_parser* %32, %struct.altera_syscons_parser** %2
br label %37
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %3
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %35)
store %struct.altera_syscons_parser* null, %struct.altera_syscons_parser** %2
br label %37
37: ; preds = %33, %31, %20, %7
%38 = load %struct.altera_syscons_parser*, %struct.altera_syscons_parser** %2
ret %struct.altera_syscons_parser* %38
}

LLVM IR (-O2):
%struct.altera_syscons_parser = type { i32 }
@altera_choose_parser.v12 = internal constant [11 x i8] c"return {12\00"
@altera_choose_parser.v13 = internal constant [11 x i8] c"return \2213\00"
@stderr = global i32 0
@.str = [28 x i8] c"Unterminated comment:\0A'%s'\0A\00"
@.str.1 = [29 x i8] c"Unknown version string '%s'\0A\00"
define %struct.altera_syscons_parser* @altera_choose_parser(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @altera_choose_parser.v12, i64 0, i64 0), i32 10)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call %struct.altera_syscons_parser* (...) @altera_get_v12_parser()
br label %26
6: ; preds = %1
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 35
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = tail call i8* @strchr(i8* %0, i8 signext 10)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* null)
br label %26
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %10, i64 1
br label %17
17: ; preds = %15, %6
%18 = phi i8* [ %16, %15 ], [ %0, %6 ]
%19 = tail call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @altera_choose_parser.v13, i64 0, i64 0), i32 10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call %struct.altera_syscons_parser* (...) @altera_get_v13_parser()
br label %26
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %26
26: ; preds = %23, %21, %12, %4
%27 = phi %struct.altera_syscons_parser* [ %5, %4 ], [ null, %12 ], [ %22, %21 ], [ null, %23 ]
ret %struct.altera_syscons_parser* %27
}