#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 utsname {
  int /*<<< orphan*/ release;
};

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ read_and_parse();
int /*<<< orphan*/ snprintf(char *, int, char const *, int /*<<< orphan*/);
scalar_t__ sysmap_mmap(char const *, void (*)(char const *));
int /*<<< orphan*/ uname(struct utsname *);
int open_psdb_message(const char *override,
                      void (*message)(const char *, ...)) {
  static const char *sysmap_paths[] = {"/boot/System.map-%s",
                                       "/boot/System.map",
                                       "/lib/modules/%s/System.map",
                                       "/usr/src/linux/System.map",
                                       "/System.map",
                                       NULL};
  struct utsname uts;
  char path[64];
  const char **fmt = sysmap_paths;
  const char *env;
  read_and_parse();
  if (override) {
    if (sysmap_mmap(override, message))
      return 0;
    return -1;
  }
  if ((env = getenv("PS_SYSMAP")) && sysmap_mmap(env, message))
    return 0;
  if ((env = getenv("PS_SYSTEM_MAP")) && sysmap_mmap(env, message))
    return 0;
  uname(&uts);
  do {
    snprintf(path, sizeof path, *fmt, uts.release);
    if (sysmap_mmap(path, message))
      return 0;
  } while (*++fmt);
  return -1;
}


x86 assembly (clang, -O0):
<open_psdb_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0x2ee9(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1040 <read_and_parse@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ac <open_psdb_message+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <sysmap_mmap@plt>
cmp    $0x0,%rax
je     11a0 <open_psdb_message+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1290 <open_psdb_message+0x140>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <open_psdb_message+0x140>
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
je     11e9 <open_psdb_message+0x99>
mov    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <sysmap_mmap@plt>
cmp    $0x0,%rax
je     11e9 <open_psdb_message+0x99>
movl   $0x0,-0x4(%rbp)
jmp    1290 <open_psdb_message+0x140>
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
je     1226 <open_psdb_message+0xd6>
mov    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <sysmap_mmap@plt>
cmp    $0x0,%rax
je     1226 <open_psdb_message+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    1290 <open_psdb_message+0x140>
lea    -0x20(%rbp),%rdi
call   1070 <uname@plt>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%ecx
mov    $0x40,%esi
call   1060 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <sysmap_mmap@plt>
cmp    $0x0,%rax
je     126a <open_psdb_message+0x11a>
movl   $0x0,-0x4(%rbp)
jmp    1290 <open_psdb_message+0x140>
jmp    126f <open_psdb_message+0x11f>
mov    -0x68(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x68(%rbp)
cmpq   $0x0,0x8(%rax)
jne    122f <open_psdb_message+0xdf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_psdb_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <read_and_parse@plt>
test   %rbp,%rbp
je     118a <open_psdb_message+0x3a>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ad <open_psdb_message+0x5d>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0xeb0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d0 <open_psdb_message+0x80>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0x8(%rsp),%rdi
call   1070 <uname@plt>
mov    0x8(%rsp),%r14d
lea    0xe1a(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0xdfc(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0xddd(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0xdc8(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <sysmap_mmap@plt>
test   %rax,%rax
jne    117d <open_psdb_message+0x2d>
lea    0xd8c(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
jmp    116c <open_psdb_message+0x1c>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@open_psdb_message.sysmap_paths = internal global [6 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str = [20 x i8] c"/boot/System.map-%s\00"
@.str.1 = [17 x i8] c"/boot/System.map\00"
@.str.2 = [27 x i8] c"/lib/modules/%s/System.map\00"
@.str.3 = [26 x i8] c"/usr/src/linux/System.map\00"
@.str.4 = [12 x i8] c"/System.map\00"
@.str.5 = [10 x i8] c"PS_SYSMAP\00"
@.str.6 = [14 x i8] c"PS_SYSTEM_MAP\00"
define i32 @open_psdb_message(i8* %0, void (i8*, ...)* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca void (i8*, ...)*
%6 = alloca %struct.utsname
%7 = alloca [64 x i8]
%8 = alloca i8**
%9 = alloca i8*
store i8* %0, i8** %4
store void (i8*, ...)* %1, void (i8*, ...)** %5
store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @open_psdb_message.sysmap_paths, i64 0, i64 0), i8*** %8
%10 = call i32 (...) @read_and_parse()
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load void (i8*, ...)*, void (i8*, ...)** %5
%16 = bitcast void (i8*, ...)* %15 to void (i8*)*
%17 = call i64 @sysmap_mmap(i8* %14, void (i8*)* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %3
br label %63
20: ; preds = %13
store i32 -1, i32* %3
br label %63
21: ; preds = %2
%22 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i8* %22, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i8*, i8** %9
%26 = load void (i8*, ...)*, void (i8*, ...)** %5
%27 = bitcast void (i8*, ...)* %26 to void (i8*)*
%28 = call i64 @sysmap_mmap(i8* %25, void (i8*)* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 0, i32* %3
br label %63
31: ; preds = %24, %21
%32 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i8* %32, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i8*, i8** %9
%36 = load void (i8*, ...)*, void (i8*, ...)** %5
%37 = bitcast void (i8*, ...)* %36 to void (i8*)*
%38 = call i64 @sysmap_mmap(i8* %35, void (i8*)* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 0, i32* %3
br label %63
41: ; preds = %34, %31
%42 = call i32 @uname(%struct.utsname* %6)
br label %43
43: ; preds = %57, %41
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%45 = load i8**, i8*** %8
%46 = load i8*, i8** %45
%47 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @snprintf(i8* %44, i32 64, i8* %46, i32 %48)
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%51 = load void (i8*, ...)*, void (i8*, ...)** %5
%52 = bitcast void (i8*, ...)* %51 to void (i8*)*
%53 = call i64 @sysmap_mmap(i8* %50, void (i8*)* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %43
store i32 0, i32* %3
br label %63
56: ; preds = %43
br label %57
57: ; preds = %56
%58 = load i8**, i8*** %8
%59 = getelementptr inbounds i8*, i8** %58, i32 1
store i8** %59, i8*** %8
%60 = load i8*, i8** %59
%61 = icmp ne i8* %60, null
br i1 %61, label %43, label %62
62: ; preds = %57
store i32 -1, i32* %3
br label %63
63: ; preds = %62, %55, %40, %30, %20, %19
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [20 x i8] c"/boot/System.map-%s\00"
@.str.1 = [17 x i8] c"/boot/System.map\00"
@.str.2 = [27 x i8] c"/lib/modules/%s/System.map\00"
@.str.3 = [26 x i8] c"/usr/src/linux/System.map\00"
@.str.4 = [12 x i8] c"/System.map\00"
@.str.5 = [10 x i8] c"PS_SYSMAP\00"
@.str.6 = [14 x i8] c"PS_SYSTEM_MAP\00"
define i32 @open_psdb_message(i8* %0, void (i8*, ...)* %1) {
%3 = alloca %struct.utsname
%4 = alloca [64 x i8]
%5 = bitcast %struct.utsname* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @read_and_parse()
%8 = icmp eq i8* %0, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = bitcast void (i8*, ...)* %1 to void (i8*)*
%11 = tail call i64 @sysmap_mmap(i8* %0, void (i8*)* %10)
%12 = icmp eq i64 %11, 0
%13 = sext i1 %12 to i32
br label %53
14: ; preds = %2
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = bitcast void (i8*, ...)* %1 to void (i8*)*
%19 = tail call i64 @sysmap_mmap(i8* %15, void (i8*)* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %17, %14
%22 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = bitcast void (i8*, ...)* %1 to void (i8*)*
%26 = tail call i64 @sysmap_mmap(i8* %22, void (i8*)* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %53
28: ; preds = %21, %24
%29 = bitcast void (i8*, ...)* %1 to void (i8*)*
%30 = call i32 @uname(%struct.utsname* %3)
%31 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i64 @sysmap_mmap(i8* %6, void (i8*)* %29)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %53
36: ; preds = %28
%37 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%38 = call i64 @sysmap_mmap(i8* %6, void (i8*)* %29)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%42 = call i64 @sysmap_mmap(i8* %6, void (i8*)* %29)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%46 = call i64 @sysmap_mmap(i8* %6, void (i8*)* %29)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%50 = call i64 @sysmap_mmap(i8* %6, void (i8*)* %29)
%51 = icmp eq i64 %50, 0
%52 = sext i1 %51 to i32
br label %53
53: ; preds = %48, %28, %36, %40, %44, %24, %17, %9
%54 = phi i32 [ %13, %9 ], [ 0, %17 ], [ 0, %24 ], [ 0, %28 ], [ 0, %36 ], [ 0, %40 ], [ 0, %44 ], [ %52, %48 ]
ret i32 %54
}