#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*/ kvlDelete(void *);
char *kvlGetListElementName(void *, int, int);
char *kvlGetListElementValue(void *, int, int);
char *kvlGetListName(void *, int);
int kvlGetListNumElements(void *, int);
int kvlGetNumLists(void *);
void *kvlParseFile(char const *);
int /*<<< orphan*/ printf(char *, ...);
int read_cmor_table(const char *filename) {
  void *kvlist;
  int nlists, listID;
  int nelements, elemID;
  const char *listname;
  const char *ename;
  const char *evalue;
  kvlist = kvlParseFile(filename);
  nlists = kvlGetNumLists(kvlist);
  printf("# Number of lists: %d\n", nlists);
  for (listID = 0; listID < nlists; ++listID) {
    listname = kvlGetListName(kvlist, listID);
    nelements = kvlGetListNumElements(kvlist, listID);
    printf("# list ID: %d;   Number of elements: %d\n", listID, nelements);
    printf("&%s\n", listname);
    for (elemID = 0; elemID < nelements; ++elemID) {
      ename = kvlGetListElementName(kvlist, listID, elemID);
      evalue = kvlGetListElementValue(kvlist, listID, elemID);
      printf("  %s = %s\n", ename, evalue);
    }
    printf("/\n");
  }
  kvlDelete(kvlist);
  return (0);
}


x86 assembly (clang, -O0):
<read_cmor_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <kvlParseFile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <kvlGetNumLists@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1287 <read_cmor_table+0x107>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <kvlGetListName@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <kvlGetListNumElements@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    126b <read_cmor_table+0xeb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <kvlGetListElementName@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1080 <kvlGetListElementValue@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1215 <read_cmor_table+0x95>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bd <read_cmor_table+0x3d>
mov    -0x10(%rbp),%rdi
call   1070 <kvlDelete@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cmor_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   10a0 <kvlParseFile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <kvlGetNumLists@plt>
mov    %eax,%ebp
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,0x4(%rsp)
test   %ebp,%ebp
jle    128d <read_cmor_table+0xfd>
lea    0xe75(%rip),%rbp
xor    %r14d,%r14d
jmp    11fb <read_cmor_table+0x6b>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     128d <read_cmor_table+0xfd>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <kvlGetListName@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <kvlGetListNumElements@plt>
mov    %eax,%r15d
lea    0xdf9(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    11e0 <read_cmor_table+0x50>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
call   1070 <kvlGetListElementName@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
call   1090 <kvlGetListElementValue@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13d
cmp    %r13d,%r15d
jne    1250 <read_cmor_table+0xc0>
jmp    11e0 <read_cmor_table+0x50>
mov    %rbx,%rdi
call   1080 <kvlDelete@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"# Number of lists: %d\0A\00"
@.str.1 = [41 x i8] c"# list ID: %d; Number of elements: %d\0A\00"
@.str.2 = [5 x i8] c"&%s\0A\00"
@.str.3 = [11 x i8] c" %s = %s\0A\00"
@.str.4 = [3 x i8] c"/\0A\00"
define i32 @read_cmor_table(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i8* @kvlParseFile(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @kvlGetNumLists(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 0, i32* %5
br label %17
17: ; preds = %54, %1
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %57
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = call i8* @kvlGetListName(i8* %22, i32 %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = call i32 @kvlGetListNumElements(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i8*, i8** %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 0, i32* %7
br label %33
33: ; preds = %49, %21
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = load i32, i32* %7
%41 = call i8* @kvlGetListElementName(i8* %38, i32 %39, i32 %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %3
%43 = load i32, i32* %5
%44 = load i32, i32* %7
%45 = call i8* @kvlGetListElementValue(i8* %42, i32 %43, i32 %44)
store i8* %45, i8** %10
%46 = load i8*, i8** %9
%47 = load i8*, i8** %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %37
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %33
52: ; preds = %33
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %17
57: ; preds = %17
%58 = load i8*, i8** %3
%59 = call i32 @kvlDelete(i8* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"# Number of lists: %d\0A\00"
@.str.1 = [41 x i8] c"# list ID: %d; Number of elements: %d\0A\00"
@.str.2 = [5 x i8] c"&%s\0A\00"
@.str.3 = [11 x i8] c" %s = %s\0A\00"
@str = [2 x i8] c"/\00"
define i32 @read_cmor_table(i8* %0) {
%2 = tail call i8* @kvlParseFile(i8* %0)
%3 = tail call i32 @kvlGetNumLists(i8* %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %24
6: ; preds = %1, %20
%7 = phi i32 [ %22, %20 ], [ 0, %1 ]
%8 = tail call i8* @kvlGetListName(i8* %2, i32 %7)
%9 = tail call i32 @kvlGetListNumElements(i8* %2, i32 %7)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%12 = icmp sgt i32 %9, 0
br i1 %12, label %13, label %20
13: ; preds = %6, %13
%14 = phi i32 [ %18, %13 ], [ 0, %6 ]
%15 = tail call i8* @kvlGetListElementName(i8* %2, i32 %7, i32 %14)
%16 = tail call i8* @kvlGetListElementValue(i8* %2, i32 %7, i32 %14)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %16)
%18 = add nuw nsw i32 %14, 1
%19 = icmp eq i32 %18, %9
br i1 %19, label %20, label %13
20: ; preds = %13, %6
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%22 = add nuw nsw i32 %7, 1
%23 = icmp eq i32 %22, %3
br i1 %23, label %24, label %6
24: ; preds = %20, %1
%25 = tail call i32 @kvlDelete(i8* %2)
ret i32 0
}