#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 extmap_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ extmap_free(struct extmap_t *);
struct extmap_t *extmap_load(char *);
int extmap_lookup(struct extmap_t *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  struct extmap_t *extmap;
  int extnum;
  if (argc < 3) {
    puts("extmaptest is a simple tool to test motsognir's extmap engine.");
    puts("usage: extmaptest file.conf ext1 [ext2] ... [extN]");
    return (1);
  }
  if (argv[1][0] == 0) {
    puts("load the default extmap...");
    extmap = extmap_load(NULL);
  } else {
    printf("load an extmap from %s...\n", argv[1]);
    extmap = extmap_load(argv[1]);
  }
  if (extmap == NULL) {
    puts("extmap_load() failed");
    return (1);
  }
  puts("perform lookups on the extmap...");
  for (extnum = 2; extnum < argc; extnum++) {
    printf("  %s -> %c\n", argv[extnum], extmap_lookup(extmap, argv[extnum]));
  }
  puts("free() the extmap...");
  extmap_free(extmap);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1194 <main+0x44>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1292 <main+0x142>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c6 <main+0x76>
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <extmap_load@plt>
mov    %rax,-0x18(%rbp)
jmp    11ed <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <extmap_load@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1210 <main+0xc0>
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1292 <main+0x142>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1276 <main+0x126>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <extmap_lookup@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <main+0xd3>
lea    0xe6d(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <extmap_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     1178 <main+0x28>
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
lea    0xecc(%rip),%rdi
jmp    1226 <main+0xd6>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%rsi
cmpb   $0x0,(%rsi)
je     119b <main+0x4b>
lea    0xeff(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r15),%rdi
jmp    11a9 <main+0x59>
lea    0xed0(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1060 <extmap_load@plt>
test   %rax,%rax
je     121f <main+0xcf>
mov    %rax,%r12
lea    0xf00(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%r13d
mov    $0x2,%ebp
lea    0xf0d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <extmap_lookup@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11e0 <main+0x90>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1030 <extmap_free@plt>
xor    %eax,%eax
jmp    1230 <main+0xe0>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.extmap_t = type { i32 }
@.str = [63 x i8] c"extmaptest is a simple tool to test motsognir's extmap engine.\00"
@.str.1 = [51 x i8] c"usage: extmaptest file.conf ext1 [ext2] ... [extN]\00"
@.str.2 = [27 x i8] c"load the default extmap...\00"
@.str.3 = [27 x i8] c"load an extmap from %s...\0A\00"
@.str.4 = [21 x i8] c"extmap_load() failed\00"
@.str.5 = [33 x i8] c"perform lookups on the extmap...\00"
@.str.6 = [12 x i8] c" %s -> %c\0A\00"
@.str.7 = [21 x i8] c"free() the extmap...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.extmap_t*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %65
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = call %struct.extmap_t* @extmap_load(i8* null)
store %struct.extmap_t* %23, %struct.extmap_t** %6
br label %33
24: ; preds = %13
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call %struct.extmap_t* @extmap_load(i8* %31)
store %struct.extmap_t* %32, %struct.extmap_t** %6
br label %33
33: ; preds = %24, %21
%34 = load %struct.extmap_t*, %struct.extmap_t** %6
%35 = icmp eq %struct.extmap_t* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %65
38: ; preds = %33
%39 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %7
br label %40
40: ; preds = %58, %38
%41 = load i32, i32* %7
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %61
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load %struct.extmap_t*, %struct.extmap_t** %6
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @extmap_lookup(%struct.extmap_t* %50, i8* %55)
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %49, i32 %56)
br label %58
58: ; preds = %44
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %40
61: ; preds = %40
%62 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%63 = load %struct.extmap_t*, %struct.extmap_t** %6
%64 = call i32 @extmap_free(%struct.extmap_t* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %61, %36, %10
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.extmap_t = type { i32 }
@.str = [63 x i8] c"extmaptest is a simple tool to test motsognir's extmap engine.\00"
@.str.1 = [51 x i8] c"usage: extmaptest file.conf ext1 [ext2] ... [extN]\00"
@.str.2 = [27 x i8] c"load the default extmap...\00"
@.str.3 = [27 x i8] c"load an extmap from %s...\0A\00"
@.str.4 = [21 x i8] c"extmap_load() failed\00"
@.str.5 = [33 x i8] c"perform lookups on the extmap...\00"
@.str.6 = [12 x i8] c" %s -> %c\0A\00"
@.str.7 = [21 x i8] c"free() the extmap...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %37
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %17
14: ; preds = %7
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%16 = load i8*, i8** %8
br label %17
17: ; preds = %14, %12
%18 = phi i8* [ %16, %14 ], [ null, %12 ]
%19 = tail call %struct.extmap_t* @extmap_load(i8* %18)
%20 = icmp eq %struct.extmap_t* %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %37
23: ; preds = %17
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%25 = zext i32 %0 to i64
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ 2, %23 ], [ %32, %26 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @extmap_lookup(%struct.extmap_t* %19, i8* %29)
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %29, i32 %30)
%32 = add nuw nsw i64 %27, 1
%33 = icmp eq i64 %32, %25
br i1 %33, label %34, label %26
34: ; preds = %26
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%36 = tail call i32 @extmap_free(%struct.extmap_t* %19)
br label %37
37: ; preds = %34, %21, %4
%38 = phi i32 [ 1, %4 ], [ 1, %21 ], [ 0, %34 ]
ret i32 %38
}