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

/* Variables and functions */
int atoi(char *);
int bpf_obj_get(char const *);
int bpf_update_elem(int, int *, int *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *,
                           int);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  const char *pinned_file = NULL;
  int ifindex = -1;
  int array_key = 0;
  int array_fd = -1;
  int ret = -1;
  int opt;
  while ((opt = getopt(argc, argv, "F:U:i:")) != -1) {
    switch (opt) {
    case 'U':
      pinned_file = optarg;
      break;
    case 'i':
      ifindex = atoi(optarg);
      break;
    default:
      usage();
      goto out;
    }
  }
  if (ifindex < 0 || !pinned_file) {
    usage();
    goto out;
  }
  array_fd = bpf_obj_get(pinned_file);
  if (array_fd < 0) {
    fprintf(stderr, "bpf_obj_get(%s): %s(%d)\n", pinned_file, strerror(errno),
            errno);
    goto out;
  }
  ret = bpf_update_elem(array_fd, &array_key, &ifindex, 0);
  if (ret) {
    perror("bpf_update_elem");
    goto out;
  }
out:
  if (array_fd != -1) {
    close(array_fd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe28(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1249 <main+0xb9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x55,%eax
je     120e <main+0x7e>
jmp    11fd <main+0x6d>
mov    -0x30(%rbp),%eax
sub    $0x69,%eax
je     1221 <main+0x91>
jmp    1238 <main+0xa8>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1244 <main+0xb4>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1244 <main+0xb4>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    12fc <main+0x16c>
jmp    11ca <main+0x3a>
cmpl   $0x0,-0x1c(%rbp)
jl     125e <main+0xce>
cmpq   $0x0,-0x18(%rbp)
jne    126a <main+0xda>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    12fc <main+0x16c>
mov    -0x18(%rbp),%rdi
call   1030 <bpf_obj_get@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12c7 <main+0x137>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
mov    0x2d1d(%rip),%rax
mov    (%rax),%r8d
lea    0xd4a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12fc <main+0x16c>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <bpf_update_elem@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     12f7 <main+0x167>
lea    0xd33(%rip),%rdi
call   1080 <perror@plt>
jmp    12fc <main+0x16c>
jmp    12fc <main+0x16c>
cmpl   $0xffffffff,-0x24(%rbp)
je     130e <main+0x17e>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x0,(%rsp)
mov    $0xffffffff,%r12d
xor    %r14d,%r14d
lea    0xe49(%rip),%r15
mov    0x2e3a(%rip),%r13
jmp    11c4 <main+0x34>
mov    0x0(%r13),%r14
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0x55,%eax
je     11c0 <main+0x30>
cmp    $0xffffffff,%eax
je     11ee <main+0x5e>
cmp    $0x69,%eax
jne    1236 <main+0xa6>
mov    0x0(%r13),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
jmp    11c4 <main+0x34>
mov    %r12d,0x4(%rsp)
test   %r12d,%r12d
js     1236 <main+0xa6>
test   %r14,%r14
je     1236 <main+0xa6>
mov    %r14,%rdi
call   1030 <bpf_obj_get@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1244 <main+0xb4>
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %ecx,%ecx
call   1060 <bpf_update_elem@plt>
test   %eax,%eax
je     127d <main+0xed>
mov    %eax,%r14d
lea    0xdf4(%rip),%rdi
call   1080 <perror@plt>
mov    %r14d,%ebx
jmp    127d <main+0xed>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0xffffffff,%ebx
jmp    1284 <main+0xf4>
mov    0x2d8d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7c(%rip),%r15
mov    (%r15),%edi
call   10b0 <strerror@plt>
mov    (%r15),%r8d
lea    0xda1(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%ebp
je     1284 <main+0xf4>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"F:U:i:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [25 x i8] c"bpf_obj_get(%s): %s(%d)\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"bpf_update_elem\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 -1, i32* %7
store i32 0, i32* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
br label %12
12: ; preds = %26, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %11
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i32, i32* %11
switch i32 %18, label %24 [
i32 85, label %19
i32 105, label %21
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %6
br label %26
21: ; preds = %17
%22 = load i8*, i8** @optarg
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
br label %26
24: ; preds = %17
%25 = call i32 (...) @usage()
br label %55
26: ; preds = %21, %19
br label %12
27: ; preds = %12
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %30, %27
%34 = call i32 (...) @usage()
br label %55
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = call i32 @bpf_obj_get(i8* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %6
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = load i32, i32* @errno
%46 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %44, i32 %45)
br label %55
47: ; preds = %35
%48 = load i32, i32* %9
%49 = call i32 @bpf_update_elem(i32 %48, i32* %8, i32* %7, i32 0)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %55
54: ; preds = %47
br label %55
55: ; preds = %54, %52, %40, %33, %24
%56 = load i32, i32* %9
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %9
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %10
ret i32 %62
}

LLVM IR (-O2):
@.str = [7 x i8] c"F:U:i:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [25 x i8] c"bpf_obj_get(%s): %s(%d)\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"bpf_update_elem\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %15, %2
%8 = phi i32 [ %17, %15 ], [ -1, %2 ]
%9 = phi i8* [ %11, %15 ], [ null, %2 ]
br label %10
10: ; preds = %7, %13
%11 = phi i8* [ %14, %13 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %18 [
i32 -1, label %20
i32 85, label %13
i32 105, label %15
]
13: ; preds = %10
%14 = load i8*, i8** @optarg
br label %10
15: ; preds = %10
%16 = load i8*, i8** @optarg
%17 = tail call i32 @atoi(i8* %16)
br label %7
18: ; preds = %10
%19 = tail call i32 (...) @usage()
br label %44
20: ; preds = %10
store i32 %8, i32* %3
%21 = icmp sgt i32 %8, -1
%22 = icmp ne i8* %11, null
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 (...) @usage()
br label %44
26: ; preds = %20
%27 = tail call i32 @bpf_obj_get(i8* %11)
%28 = icmp slt i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = call i32 @bpf_update_elem(i32 %27, i32* %4, i32* %3, i32 0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %41
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = load i32, i32* @errno
%39 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %37, i32 %38)
%40 = icmp eq i32 %27, -1
br i1 %40, label %44, label %41
41: ; preds = %29, %32, %34
%42 = phi i32 [ -1, %34 ], [ 0, %29 ], [ %30, %32 ]
%43 = call i32 @close(i32 %27)
br label %44
44: ; preds = %24, %18, %41, %34
%45 = phi i32 [ %42, %41 ], [ -1, %34 ], [ -1, %18 ], [ -1, %24 ]
ret i32 %45
}