#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int bpf_lookup_elem(int, int *, int *);
int bpf_map_create();
int bpf_obj_get(char const *);
int bpf_obj_pin(int, char const *);
int bpf_update_elem(int, int *, int *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, int, ...);
char *strerror(int /*<<< orphan*/);
int bpf_do_map(const char *file, uint32_t flags, uint32_t key, uint32_t value) {
  int fd, ret;
  if (flags & (1 << 0)) {
    fd = bpf_map_create();
    printf("bpf: map fd:%d (%s)\n", fd, strerror(errno));
    assert(fd > 0);
    ret = bpf_obj_pin(fd, file);
    printf("bpf: pin ret:(%d,%s)\n", ret, strerror(errno));
    assert(ret == 0);
  } else {
    fd = bpf_obj_get(file);
    printf("bpf: get fd:%d (%s)\n", fd, strerror(errno));
    assert(fd > 0);
  }
  if ((flags & ((1 << 2) | (1 << 3))) == ((1 << 2) | (1 << 3))) {
    ret = bpf_update_elem(fd, &key, &value, 0);
    printf("bpf: fd:%d u->(%u:%u) ret:(%d,%s)\n", fd, key, value, ret,
           strerror(errno));
    assert(ret == 0);
  } else if (flags & (1 << 2)) {
    ret = bpf_lookup_elem(fd, &key, &value);
    printf("bpf: fd:%d l->(%u):%u ret:(%d,%s)\n", fd, key, value, ret,
           strerror(errno));
    assert(ret == 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<bpf_do_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1234 <bpf_do_map+0xb4>
mov    $0x0,%al
call   1070 <bpf_map_create@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <bpf_obj_pin@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1279 <bpf_do_map+0xf9>
mov    -0x8(%rbp),%rdi
call   1040 <bpf_obj_get@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x28(%rbp),%esi
mov    %rax,%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0xc(%rbp),%eax
and    $0xc,%eax
cmp    $0xc,%eax
jne    12f7 <bpf_do_map+0x177>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
xor    %ecx,%ecx
call   1080 <bpf_update_elem@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    %rax,%r9
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1373 <bpf_do_map+0x1f3>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     136e <bpf_do_map+0x1ee>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1090 <bpf_lookup_elem@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    %rax,%r9
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1373 <bpf_do_map+0x1f3>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_do_map>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %edx,0x4(%rsp)
mov    %ecx,(%rsp)
test   $0x1,%r14b
jne    11cc <bpf_do_map+0x4c>
mov    %rbp,%rdi
call   1040 <bpf_obj_get@plt>
mov    %eax,%ebx
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe72(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
setg   %al
jmp    1230 <bpf_do_map+0xb0>
xor    %eax,%eax
call   1070 <bpf_map_create@plt>
mov    %eax,%ebx
mov    0x2e04(%rip),%r15
mov    (%r15),%edi
call   10a0 <strerror@plt>
lea    0xe15(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1060 <assert@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <bpf_obj_pin@plt>
mov    %eax,%ebp
mov    (%r15),%edi
call   10a0 <strerror@plt>
lea    0xdf6(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
sete   %al
movzbl %al,%edi
call   1060 <assert@plt>
mov    %r14d,%eax
not    %eax
test   $0xc,%al
jne    1274 <bpf_do_map+0xf4>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
xor    %ecx,%ecx
call   1080 <bpf_update_elem@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%r14d
mov    (%rsp),%r15d
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdce(%rip),%rdi
jmp    12a9 <bpf_do_map+0x129>
test   $0x4,%r14b
je     12cb <bpf_do_map+0x14b>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1090 <bpf_lookup_elem@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%r14d
mov    (%rsp),%r15d
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdba(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
test   %ebp,%ebp
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"bpf: map fd:%d (%s)\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"bpf: pin ret:(%d,%s)\0A\00"
@.str.2 = [21 x i8] c"bpf: get fd:%d (%s)\0A\00"
@.str.3 = [35 x i8] c"bpf: fd:%d u->(%u:%u) ret:(%d,%s)\0A\00"
@.str.4 = [35 x i8] c"bpf: fd:%d l->(%u):%u ret:(%d,%s)\0A\00"
define i32 @bpf_do_map(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = and i32 %11, 1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %4
%15 = call i32 (...) @bpf_map_create()
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %18)
%20 = load i32, i32* %9
%21 = icmp sgt i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %9
%25 = load i8*, i8** %5
%26 = call i32 @bpf_obj_pin(i32 %24, i8* %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %29)
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %46
35: ; preds = %4
%36 = load i8*, i8** %5
%37 = call i32 @bpf_obj_get(i8* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* %40)
%42 = load i32, i32* %9
%43 = icmp sgt i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
br label %46
46: ; preds = %35, %14
%47 = load i32, i32* %6
%48 = and i32 %47, 12
%49 = icmp eq i32 %48, 12
br i1 %49, label %50, label %64
50: ; preds = %46
%51 = load i32, i32* %9
%52 = call i32 @bpf_update_elem(i32 %51, i32* %7, i32* %8, i32 0)
store i32 %52, i32* %10
%53 = load i32, i32* %9
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = load i32, i32* %10
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %54, i32 %55, i32 %56, i8* %58)
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
br label %83
64: ; preds = %46
%65 = load i32, i32* %6
%66 = and i32 %65, 4
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %82
68: ; preds = %64
%69 = load i32, i32* %9
%70 = call i32 @bpf_lookup_elem(i32 %69, i32* %7, i32* %8)
store i32 %70, i32* %10
%71 = load i32, i32* %9
%72 = load i32, i32* %7
%73 = load i32, i32* %8
%74 = load i32, i32* %10
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %71, i32 %72, i32 %73, i32 %74, i8* %76)
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, 0
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
br label %82
82: ; preds = %68, %64
br label %83
83: ; preds = %82, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"bpf: map fd:%d (%s)\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"bpf: pin ret:(%d,%s)\0A\00"
@.str.2 = [21 x i8] c"bpf: get fd:%d (%s)\0A\00"
@.str.3 = [35 x i8] c"bpf: fd:%d u->(%u:%u) ret:(%d,%s)\0A\00"
@.str.4 = [35 x i8] c"bpf: fd:%d l->(%u):%u ret:(%d,%s)\0A\00"
define i32 @bpf_do_map(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
store i32 %2, i32* %5
store i32 %3, i32* %6
%7 = and i32 %1, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = tail call i32 (...) @bpf_map_create()
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %12)
%14 = icmp sgt i32 %10, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @bpf_obj_pin(i32 %10, i8* %0)
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %19)
%21 = icmp eq i32 %17, 0
br label %28
22: ; preds = %4
%23 = tail call i32 @bpf_obj_get(i8* %0)
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %25)
%27 = icmp sgt i32 %23, 0
br label %28
28: ; preds = %22, %9
%29 = phi i1 [ %27, %22 ], [ %21, %9 ]
%30 = phi i32 [ %23, %22 ], [ %10, %9 ]
%31 = zext i1 %29 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = and i32 %1, 12
%34 = icmp eq i32 %33, 12
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = call i32 @bpf_update_elem(i32 %30, i32* %5, i32* %6, i32 0)
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %37, i32 %38, i32 %36, i8* %40)
br label %52
42: ; preds = %28
%43 = and i32 %1, 4
%44 = icmp eq i32 %43, 0
br i1 %44, label %57, label %45
45: ; preds = %42
%46 = call i32 @bpf_lookup_elem(i32 %30, i32* %5, i32* %6)
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %47, i32 %48, i32 %46, i8* %50)
br label %52
52: ; preds = %35, %45
%53 = phi i32 [ %46, %45 ], [ %36, %35 ]
%54 = icmp eq i32 %53, 0
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
br label %57
57: ; preds = %52, %42
ret i32 0
}