#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ ll_get_attribute(char const *, char *, int);
int /*<<< orphan*/ ll_get_first(int /*<<< orphan*/);
int /*<<< orphan*/ ll_int_arrays_equal(int *, int *);
int *ll_parse_version(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void test_get_version() {
  int known_good_version[] = {2, 2, 0};
  const char *license;
  int *version;
  license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
  version = ll_parse_version(ll_get_first(
      ll_get_attribute(license, "http://purl.org/dc/terms/hasVersion", false)));
  printf("get_version: ");
  assert(ll_int_arrays_equal(version, known_good_version));
  if (version) {
    int i;
    for (i = 1; i <= version[0]; ++i) {
      if (i != 1)
        printf(".");
      printf("%d", version[i]);
    }
    printf("\n");
    free(version);
  } else {
    printf("unversioned\n");
  }
}


x86 assembly (clang, -O0):
<test_get_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe81(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xe7f(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
xor    %edx,%edx
call   1040 <ll_get_attribute@plt>
mov    %eax,%edi
call   1090 <ll_get_first@plt>
mov    %eax,%edi
call   1060 <ll_parse_version@plt>
mov    %rax,-0x20(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <ll_int_arrays_equal@plt>
mov    %eax,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
je     1259 <test_get_version+0xe9>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     123d <test_get_version+0xcd>
cmpl   $0x1,-0x24(%rbp)
je     1216 <test_get_version+0xa6>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ef <test_get_version+0x7f>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1267 <test_get_version+0xf7>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_version>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0xe69(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xe56(%rip),%rax
mov    %rax,(%rsp)
lea    0xe57(%rip),%rdi
lea    0xe82(%rip),%rsi
xor    %edx,%edx
call   1060 <ll_get_attribute@plt>
mov    %eax,%edi
call   10b0 <ll_get_first@plt>
mov    %eax,%edi
call   1080 <ll_parse_version@plt>
mov    %rax,%r15
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   10a0 <ll_int_arrays_equal@plt>
mov    %eax,%edi
call   1090 <assert@plt>
test   %r15,%r15
je     1269 <test_get_version+0xd9>
cmpl   $0x0,(%r15)
jle    1255 <test_get_version+0xc5>
mov    0x4(%r15),%esi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x2,(%r15)
jl     1255 <test_get_version+0xc5>
mov    $0x1,%ebx
lea    0xe4d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x2e,%edi
call   1040 <putchar@plt>
mov    0x4(%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movslq (%r15),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1230 <test_get_version+0xa0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1275 <test_get_version+0xe5>
lea    0xe03(%rip),%rdi
call   1050 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_get_version.known_good_version = [3 x i32] [i32 2, i32 2, i32 0]
@.str = [50 x i8] c"http://creativecommons.org/licenses/by-nd/2.0/de/\00"
@.str.1 = [36 x i8] c"http://purl.org/dc/terms/hasVersion\00"
@.str.2 = [14 x i8] c"get_version: \00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [13 x i8] c"unversioned\0A\00"
define void @test_get_version() {
%1 = alloca [3 x i32]
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = bitcast [3 x i32]* %1 to i8*
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @ll_get_attribute(i8* %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 0)
%8 = call i32 @ll_get_first(i32 %7)
%9 = call i32* @ll_parse_version(i32 %8)
store i32* %9, i32** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%13 = call i32 @ll_int_arrays_equal(i32* %11, i32* %12)
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %43
17: ; preds = %0
store i32 1, i32* %4
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %4
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
%23 = icmp sle i32 %19, %22
br i1 %23, label %24, label %39
24: ; preds = %18
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = load i32*, i32** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %18
39: ; preds = %18
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32*, i32** %3
%42 = call i32 @free(i32* %41)
br label %45
43: ; preds = %0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
ret void
}

LLVM IR (-O2):
@__const.test_get_version.known_good_version = [3 x i32] [i32 2, i32 2, i32 0]
@.str = [50 x i8] c"http://creativecommons.org/licenses/by-nd/2.0/de/\00"
@.str.1 = [36 x i8] c"http://purl.org/dc/terms/hasVersion\00"
@.str.2 = [14 x i8] c"get_version: \00"
@.str.4 = [3 x i8] c"%d\00"
@str = [12 x i8] c"unversioned\00"
define void @test_get_version() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = tail call i32 @ll_get_attribute(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 0)
%4 = tail call i32 @ll_get_first(i32 %3)
%5 = tail call i32* @ll_parse_version(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%8 = call i32 @ll_int_arrays_equal(i32* %5, i32* %7)
%9 = call i32 @assert(i32 %8)
%10 = icmp eq i32* %5, null
br i1 %10, label %33, label %11
11: ; preds = %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 1
br i1 %13, label %30, label %14
14: ; preds = %11
%15 = getelementptr inbounds i32, i32* %5, i64 1
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %30
20: ; preds = %14, %20
%21 = phi i64 [ %26, %20 ], [ 2, %14 ]
%22 = call i32 @putchar(i32 46)
%23 = getelementptr inbounds i32, i32* %5, i64 %21
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %21, 1
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %21, %28
br i1 %29, label %20, label %30
30: ; preds = %20, %14, %11
%31 = call i32 @putchar(i32 10)
%32 = call i32 @free(i32* %5)
br label %35
33: ; preds = %0
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
ret void
}