#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*/ path;

/* Variables and functions */
void *roadmap_canvas_load_image(char const *, char const *);
char *roadmap_lang_get_system_lang();
char *roadmap_path_first(char *);
int /*<<< orphan*/ roadmap_path_format(char *, int, char const *, char *);
char *roadmap_path_next(char *, char const *);
char *roadmap_path_user();
void *roadmap_sound_load(char const *, char const *, int *);
void *load_resource(unsigned int type, unsigned int flags, const char *name,
                    int *mem) {
  const char *cursor;
  void *data = NULL;
  if (flags & 0x1) {
    for (cursor = roadmap_path_first("skin"); cursor != NULL;
         cursor = roadmap_path_next("skin", cursor)) {
      switch (type) {
      case 0:
        *mem = 0;
        data = roadmap_canvas_load_image(cursor, name);
        break;
      case 1:
        data = roadmap_sound_load(cursor, name, mem);
        break;
      }
      if (data)
        break;
    }
  } else {
    const char *user_path = roadmap_path_user();
    char path[512];
    switch (type) {
    case 0:
      *mem = 0;
      roadmap_path_format(path, sizeof(path), user_path, "icons");
      data = roadmap_canvas_load_image(path, name);
      break;
    case 1:
      roadmap_path_format(path, sizeof(path), user_path, "sound");
      roadmap_path_format(path, sizeof(path), path,
                          roadmap_lang_get_system_lang());
      data = roadmap_sound_load(path, name, mem);
      break;
    }
  }
  return data;
}


x86 assembly (clang, -O0):
<load_resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     124d <load_resource+0xdd>
lea    0xe59(%rip),%rdi
call   1080 <roadmap_path_first@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1248 <load_resource+0xd8>
mov    -0x4(%rbp),%eax
mov    %eax,-0x234(%rbp)
test   %eax,%eax
je     11e5 <load_resource+0x75>
jmp    11d1 <load_resource+0x61>
mov    -0x234(%rbp),%eax
sub    $0x1,%eax
je     1205 <load_resource+0x95>
jmp    121a <load_resource+0xaa>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <roadmap_canvas_load_image@plt>
mov    %rax,-0x28(%rbp)
jmp    121a <load_resource+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <roadmap_sound_load@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     122a <load_resource+0xba>
jmp    1248 <load_resource+0xd8>
jmp    122f <load_resource+0xbf>
mov    -0x20(%rbp),%rsi
lea    0xdc6(%rip),%rdi
call   1040 <roadmap_path_next@plt>
mov    %rax,-0x20(%rbp)
jmp    11b0 <load_resource+0x40>
jmp    1338 <load_resource+0x1c8>
xor    %eax,%eax
call   1070 <roadmap_path_user@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x238(%rbp)
test   %eax,%eax
je     1282 <load_resource+0x112>
jmp    126e <load_resource+0xfe>
mov    -0x238(%rbp),%eax
sub    $0x1,%eax
je     12c1 <load_resource+0x151>
jmp    1333 <load_resource+0x1c3>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x230(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x200,%esi
lea    0xd62(%rip),%rcx
call   1050 <roadmap_path_format@plt>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <roadmap_canvas_load_image@plt>
mov    %rax,-0x28(%rbp)
jmp    1333 <load_resource+0x1c3>
lea    -0x230(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x200,%esi
lea    0xd33(%rip),%rcx
call   1050 <roadmap_path_format@plt>
lea    -0x230(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    $0x0,%al
call   1030 <roadmap_lang_get_system_lang@plt>
mov    -0x248(%rbp),%rdi
mov    -0x240(%rbp),%rdx
mov    %rax,%rcx
mov    $0x200,%esi
call   1050 <roadmap_path_format@plt>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <roadmap_sound_load@plt>
mov    %rax,-0x28(%rbp)
jmp    1338 <load_resource+0x1c8>
mov    -0x28(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_resource>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %edi,%r13d
test   $0x1,%sil
jne    11dd <load_resource+0x6d>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <roadmap_path_user@plt>
cmp    $0x1,%r13d
je     124c <load_resource+0xdc>
test   %r13d,%r13d
jne    1291 <load_resource+0x121>
movl   $0x0,(%r15)
lea    0xe4b(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <roadmap_path_format@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <roadmap_canvas_load_image@plt>
jmp    128e <load_resource+0x11e>
lea    0xe1c(%rip),%rdi
call   1080 <roadmap_path_first@plt>
test   %rax,%rax
je     1248 <load_resource+0xd8>
mov    %rax,%rbx
lea    0xe08(%rip),%r12
jmp    1229 <load_resource+0xb9>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <roadmap_sound_load@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1291 <load_resource+0x121>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <roadmap_path_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1248 <load_resource+0xd8>
cmp    $0x1,%r13d
je     1200 <load_resource+0x90>
test   %r13d,%r13d
jne    1216 <load_resource+0xa6>
movl   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <roadmap_canvas_load_image@plt>
jmp    120e <load_resource+0x9e>
xor    %ebp,%ebp
jmp    1291 <load_resource+0x121>
lea    0xdb8(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <roadmap_path_format@plt>
xor    %eax,%eax
call   1030 <roadmap_lang_get_system_lang@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <roadmap_path_format@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <roadmap_sound_load@plt>
mov    %rax,%rbp
mov    %rbp,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"skin\00"
@.str.1 = [6 x i8] c"icons\00"
@.str.2 = [6 x i8] c"sound\00"
define i8* @load_resource(i32 %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca [512 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i8* null, i8** %10
%13 = load i32, i32* %6
%14 = and i32 %13, 1
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %4
%17 = call i8* @roadmap_path_first(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %9
br label %18
18: ; preds = %38, %16
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i32, i32* %5
switch i32 %22, label %33 [
i32 0, label %23
i32 1, label %28
]
23: ; preds = %21
%24 = load i32*, i32** %8
store i32 0, i32* %24
%25 = load i8*, i8** %9
%26 = load i8*, i8** %7
%27 = call i8* @roadmap_canvas_load_image(i8* %25, i8* %26)
store i8* %27, i8** %10
br label %33
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = load i8*, i8** %7
%31 = load i32*, i32** %8
%32 = call i8* @roadmap_sound_load(i8* %29, i8* %30, i32* %31)
store i8* %32, i8** %10
br label %33
33: ; preds = %21, %28, %23
%34 = load i8*, i8** %10
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %33
br label %41
37: ; preds = %33
br label %38
38: ; preds = %37
%39 = load i8*, i8** %9
%40 = call i8* @roadmap_path_next(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %39)
store i8* %40, i8** %9
br label %18
41: ; preds = %36, %18
br label %66
42: ; preds = %4
%43 = call i8* (...) @roadmap_path_user()
store i8* %43, i8** %11
%44 = load i32, i32* %5
switch i32 %44, label %65 [
i32 0, label %45
i32 1, label %53
]
45: ; preds = %42
%46 = load i32*, i32** %8
store i32 0, i32* %46
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%48 = load i8*, i8** %11
%49 = call i32 @roadmap_path_format(i8* %47, i32 512, i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = call i8* @roadmap_canvas_load_image(i8* %50, i8* %51)
store i8* %52, i8** %10
br label %65
53: ; preds = %42
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%55 = load i8*, i8** %11
%56 = call i32 @roadmap_path_format(i8* %54, i32 512, i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%59 = call i8* (...) @roadmap_lang_get_system_lang()
%60 = call i32 @roadmap_path_format(i8* %57, i32 512, i8* %58, i8* %59)
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%62 = load i8*, i8** %7
%63 = load i32*, i32** %8
%64 = call i8* @roadmap_sound_load(i8* %61, i8* %62, i32* %63)
store i8* %64, i8** %10
br label %65
65: ; preds = %42, %53, %45
br label %66
66: ; preds = %65, %41
%67 = load i8*, i8** %10
ret i8* %67
}

LLVM IR (-O2):
@.str = [5 x i8] c"skin\00"
@.str.1 = [6 x i8] c"icons\00"
@.str.2 = [6 x i8] c"sound\00"
define i8* @load_resource(i32 %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca [512 x i8]
%6 = and i32 %1, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %4
%9 = tail call i8* @roadmap_path_first(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %36, label %11
11: ; preds = %8, %20
%12 = phi i8* [ %21, %20 ], [ %9, %8 ]
switch i32 %0, label %20 [
i32 0, label %13
i32 1, label %15
]
13: ; preds = %11
store i32 0, i32* %3
%14 = tail call i8* @roadmap_canvas_load_image(i8* %12, i8* %2)
br label %17
15: ; preds = %11
%16 = tail call i8* @roadmap_sound_load(i8* %12, i8* %2, i32* %3)
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %16, %15 ], [ %14, %13 ]
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %36
20: ; preds = %11, %17
%21 = tail call i8* @roadmap_path_next(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12)
%22 = icmp eq i8* %21, null
br i1 %22, label %36, label %11
23: ; preds = %4
%24 = tail call i8* (...) @roadmap_path_user()
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
switch i32 %0, label %34 [
i32 0, label %26
i32 1, label %29
]
26: ; preds = %23
store i32 0, i32* %3
%27 = call i32 @roadmap_path_format(i8* %25, i32 512, i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = call i8* @roadmap_canvas_load_image(i8* %25, i8* %2)
br label %34
29: ; preds = %23
%30 = call i32 @roadmap_path_format(i8* %25, i32 512, i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = call i8* (...) @roadmap_lang_get_system_lang()
%32 = call i32 @roadmap_path_format(i8* %25, i32 512, i8* %25, i8* %31)
%33 = call i8* @roadmap_sound_load(i8* %25, i8* %2, i32* %3)
br label %34
34: ; preds = %23, %29, %26
%35 = phi i8* [ null, %23 ], [ %33, %29 ], [ %28, %26 ]
br label %36
36: ; preds = %17, %20, %8, %34
%37 = phi i8* [ %35, %34 ], [ null, %8 ], [ %18, %17 ], [ null, %20 ]
ret i8* %37
}