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

/* Variables and functions */
struct link_map *get_vdso_from_aliases();
struct link_map *get_vdso_from_auxv();
struct link_map *get_vdso_from_maps();
int is_vdso(struct link_map *map) {
  static int vdso_checked = 0;
  static struct link_map *vdso = NULL;
  struct link_map *result;
  if (!map)
    return 0;
  if (vdso_checked)
    return (map == vdso);
  vdso_checked = 1;
  result = get_vdso_from_aliases();
  if (result) {
    vdso = result;
    return (map == vdso);
  }
  result = get_vdso_from_auxv();
  if (result) {
    vdso = result;
    return (map == vdso);
  }
  result = get_vdso_from_maps();
  if (result) {
    vdso = result;
    return (map == vdso);
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_vdso>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <is_vdso+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1240 <is_vdso+0x110>
cmpl   $0x0,0x2ee6(%rip)
je     117b <is_vdso+0x4b>
mov    -0x10(%rbp),%rax
cmp    0x2edd(%rip),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <is_vdso+0x110>
movl   $0x1,0x2ebb(%rip)
mov    $0x0,%al
call   1050 <get_vdso_from_aliases@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c1 <is_vdso+0x91>
mov    -0x18(%rbp),%rax
mov    %rax,0x2ea2(%rip)
mov    -0x10(%rbp),%rax
cmp    0x2e97(%rip),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <is_vdso+0x110>
mov    $0x0,%al
call   1030 <get_vdso_from_auxv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fd <is_vdso+0xcd>
mov    -0x18(%rbp),%rax
mov    %rax,0x2e66(%rip)
mov    -0x10(%rbp),%rax
cmp    0x2e5b(%rip),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <is_vdso+0x110>
mov    $0x0,%al
call   1040 <get_vdso_from_maps@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1239 <is_vdso+0x109>
mov    -0x18(%rbp),%rax
mov    %rax,0x2e2a(%rip)
mov    -0x10(%rbp),%rax
cmp    0x2e1f(%rip),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <is_vdso+0x110>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_vdso>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     114d <is_vdso+0x1d>
mov    %rdi,%rbx
cmpb   $0x1,0x2efe(%rip)
jne    1151 <is_vdso+0x21>
cmp    %rbx,0x2efd(%rip)
jmp    1188 <is_vdso+0x58>
xor    %ebp,%ebp
jmp    118c <is_vdso+0x5c>
movb   $0x1,0x2ee8(%rip)
xor    %eax,%eax
call   1050 <get_vdso_from_aliases@plt>
test   %rax,%rax
jne    117e <is_vdso+0x4e>
xor    %eax,%eax
call   1030 <get_vdso_from_auxv@plt>
test   %rax,%rax
jne    117e <is_vdso+0x4e>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <get_vdso_from_maps@plt>
test   %rax,%rax
je     118c <is_vdso+0x5c>
mov    %rax,0x2ec3(%rip)
cmp    %rbx,%rax
sete   %bpl
movzbl %bpl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.link_map = type { i32 }
@is_vdso.vdso_checked = internal global i32 0
@is_vdso.vdso = internal global %struct.link_map* null
define i32 @is_vdso(%struct.link_map* %0) {
%2 = alloca i32
%3 = alloca %struct.link_map*
%4 = alloca %struct.link_map*
store %struct.link_map* %0, %struct.link_map** %3
%5 = load %struct.link_map*, %struct.link_map** %3
%6 = icmp ne %struct.link_map* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %47
8: ; preds = %1
%9 = load i32, i32* @is_vdso.vdso_checked
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load %struct.link_map*, %struct.link_map** %3
%13 = load %struct.link_map*, %struct.link_map** @is_vdso.vdso
%14 = icmp eq %struct.link_map* %12, %13
%15 = zext i1 %14 to i32
store i32 %15, i32* %2
br label %47
16: ; preds = %8
store i32 1, i32* @is_vdso.vdso_checked
%17 = call %struct.link_map* (...) @get_vdso_from_aliases()
store %struct.link_map* %17, %struct.link_map** %4
%18 = load %struct.link_map*, %struct.link_map** %4
%19 = icmp ne %struct.link_map* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load %struct.link_map*, %struct.link_map** %4
store %struct.link_map* %21, %struct.link_map** @is_vdso.vdso
%22 = load %struct.link_map*, %struct.link_map** %3
%23 = load %struct.link_map*, %struct.link_map** @is_vdso.vdso
%24 = icmp eq %struct.link_map* %22, %23
%25 = zext i1 %24 to i32
store i32 %25, i32* %2
br label %47
26: ; preds = %16
%27 = call %struct.link_map* (...) @get_vdso_from_auxv()
store %struct.link_map* %27, %struct.link_map** %4
%28 = load %struct.link_map*, %struct.link_map** %4
%29 = icmp ne %struct.link_map* %28, null
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load %struct.link_map*, %struct.link_map** %4
store %struct.link_map* %31, %struct.link_map** @is_vdso.vdso
%32 = load %struct.link_map*, %struct.link_map** %3
%33 = load %struct.link_map*, %struct.link_map** @is_vdso.vdso
%34 = icmp eq %struct.link_map* %32, %33
%35 = zext i1 %34 to i32
store i32 %35, i32* %2
br label %47
36: ; preds = %26
%37 = call %struct.link_map* (...) @get_vdso_from_maps()
store %struct.link_map* %37, %struct.link_map** %4
%38 = load %struct.link_map*, %struct.link_map** %4
%39 = icmp ne %struct.link_map* %38, null
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load %struct.link_map*, %struct.link_map** %4
store %struct.link_map* %41, %struct.link_map** @is_vdso.vdso
%42 = load %struct.link_map*, %struct.link_map** %3
%43 = load %struct.link_map*, %struct.link_map** @is_vdso.vdso
%44 = icmp eq %struct.link_map* %42, %43
%45 = zext i1 %44 to i32
store i32 %45, i32* %2
br label %47
46: ; preds = %36
store i32 0, i32* %2
br label %47
47: ; preds = %46, %40, %30, %20, %11, %7
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.link_map = type { i32 }
@is_vdso.vdso_checked = internal unnamed_addr global i1 false
@is_vdso.vdso = internal unnamed_addr global %struct.link_map* null
define i32 @is_vdso(%struct.link_map* readnone %0) {
%2 = icmp eq %struct.link_map* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = load i1, i1* @is_vdso.vdso_checked
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = load %struct.link_map*, %struct.link_map** @is_vdso.vdso
%7 = icmp eq %struct.link_map* %6, %0
br label %23
8: ; preds = %3
store i1 true, i1* @is_vdso.vdso_checked
%9 = tail call %struct.link_map* (...) @get_vdso_from_aliases()
%10 = icmp eq %struct.link_map* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
store %struct.link_map* %9, %struct.link_map** @is_vdso.vdso
%12 = icmp eq %struct.link_map* %9, %0
br label %23
13: ; preds = %8
%14 = tail call %struct.link_map* (...) @get_vdso_from_auxv()
%15 = icmp eq %struct.link_map* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
store %struct.link_map* %14, %struct.link_map** @is_vdso.vdso
%17 = icmp eq %struct.link_map* %14, %0
br label %23
18: ; preds = %13
%19 = tail call %struct.link_map* (...) @get_vdso_from_maps()
%20 = icmp eq %struct.link_map* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
store %struct.link_map* %19, %struct.link_map** @is_vdso.vdso
%22 = icmp eq %struct.link_map* %19, %0
br label %23
23: ; preds = %18, %1, %21, %16, %11, %5
%24 = phi i1 [ %7, %5 ], [ %12, %11 ], [ %17, %16 ], [ %22, %21 ], [ false, %1 ], [ false, %18 ]
%25 = zext i1 %24 to i32
ret i32 %25
}