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

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int atoi(char *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ setsysctrl(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  char device[IFNAMSIZ + 1];
  int distance = -1;
  int c;
  strncpy(device, "wifi0", sizeof(device));
  for (;;) {
    c = getopt(argc, argv, "d:i:h");
    if (c < 0)
      break;
    switch (c) {
    case 'h':
      usage();
      break;
    case 'd':
      distance = atoi(optarg);
      break;
    case 'i':
      strncpy(device, optarg, sizeof(device));
      break;
    default:
      usage();
      break;
    }
  }
  if (distance >= 0) {
    printf("Setting distance on interface %s to %i meters\n", device, distance);
    setsysctrl(device, "distance", distance);
  } else
    usage();
  return 0;
}


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)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    %eax,%edx
lea    0xe47(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3a(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11e3 <main+0x83>
jmp    1266 <main+0x106>
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x64,%eax
je     1225 <main+0xc5>
jmp    11f7 <main+0x97>
mov    -0x3c(%rbp),%eax
sub    $0x68,%eax
je     1219 <main+0xb9>
jmp    1208 <main+0xa8>
mov    -0x3c(%rbp),%eax
sub    $0x69,%eax
je     123c <main+0xdc>
jmp    125a <main+0xfa>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    1261 <main+0x101>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    1261 <main+0x101>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    1261 <main+0x101>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    11be <main+0x5e>
cmpl   $0x0,-0x24(%rbp)
jl     129b <main+0x13b>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xd8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdaa(%rip),%rsi
call   1060 <setsysctrl@plt>
jmp    12a2 <main+0x142>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e5e(%rip),%rax
mov    (%rax),%r12d
add    $0x1,%r12d
mov    %rsp,%r14
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
call   1030 <strncpy@plt>
lea    0xe5a(%rip),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <getopt@plt>
test   %eax,%eax
js     124f <main+0xef>
movl   $0xffffffff,-0x2c(%rbp)
lea    0xe3a(%rip),%r13
jmp    11f6 <main+0x96>
xchg   %ax,%ax
mov    0x2e21(%rip),%rax
mov    (%rax),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
call   1030 <strncpy@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   1070 <getopt@plt>
test   %eax,%eax
js     1224 <main+0xc4>
cmp    $0x64,%eax
je     1210 <main+0xb0>
cmp    $0x69,%eax
je     11d0 <main+0x70>
cmp    $0x68,%eax
xor    %eax,%eax
call   1050 <usage@plt>
jmp    11e5 <main+0x85>
nopl   0x0(%rax)
mov    0x2de1(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    11e5 <main+0x85>
mov    -0x2c(%rbp),%ebx
test   %ebx,%ebx
js     124f <main+0xef>
lea    0xdda(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
lea    0xdf8(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <setsysctrl@plt>
jmp    1256 <main+0xf6>
xor    %eax,%eax
call   1050 <usage@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IFNAMSIZ = global i32 0
@.str = [6 x i8] c"wifi0\00"
@.str.1 = [6 x i8] c"d:i:h\00"
@optarg = global i8* null
@.str.2 = [47 x i8] c"Setting distance on interface %s to %i meters\0A\00"
@.str.3 = [9 x i8] c"distance\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @IFNAMSIZ
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
store i32 -1, i32* %8
%15 = trunc i64 %12 to i32
%16 = call i32 @strncpy(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %37, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %38
24: ; preds = %17
%25 = load i32, i32* %9
switch i32 %25, label %35 [
i32 104, label %26
i32 100, label %28
i32 105, label %31
]
26: ; preds = %24
%27 = call i32 (...) @usage()
br label %37
28: ; preds = %24
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
br label %37
31: ; preds = %24
%32 = load i8*, i8** @optarg
%33 = trunc i64 %12 to i32
%34 = call i32 @strncpy(i8* %14, i8* %32, i32 %33)
br label %37
35: ; preds = %24
%36 = call i32 (...) @usage()
br label %37
37: ; preds = %35, %31, %28, %26
br label %17
38: ; preds = %23
%39 = load i32, i32* %8
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load i32, i32* %8
%43 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %42)
%44 = load i32, i32* %8
%45 = call i32 @setsysctrl(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %48
46: ; preds = %38
%47 = call i32 (...) @usage()
br label %48
48: ; preds = %46, %41
store i32 0, i32* %3
%49 = load i8*, i8** %6
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@IFNAMSIZ = global i32 0
@.str = [6 x i8] c"wifi0\00"
@.str.1 = [6 x i8] c"d:i:h\00"
@optarg = global i8* null
@.str.2 = [47 x i8] c"Setting distance on interface %s to %i meters\0A\00"
@.str.3 = [9 x i8] c"distance\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @IFNAMSIZ
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp slt i32 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %2, %23
%11 = phi i32 [ %25, %23 ], [ %8, %2 ]
%12 = phi i32 [ %24, %23 ], [ -1, %2 ]
switch i32 %11, label %21 [
i32 104, label %13
i32 100, label %15
i32 105, label %18
]
13: ; preds = %10
%14 = call i32 (...) @usage()
br label %23
15: ; preds = %10
%16 = load i8*, i8** @optarg
%17 = call i32 @atoi(i8* %16)
br label %23
18: ; preds = %10
%19 = load i8*, i8** @optarg
%20 = call i32 @strncpy(i8* %6, i8* %19, i32 %4)
br label %23
21: ; preds = %10
%22 = call i32 (...) @usage()
br label %23
23: ; preds = %21, %18, %15, %13
%24 = phi i32 [ %12, %21 ], [ %12, %18 ], [ %17, %15 ], [ %12, %13 ]
%25 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %10
27: ; preds = %23
%28 = icmp sgt i32 %24, -1
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %24)
%31 = call i32 @setsysctrl(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %34
32: ; preds = %2, %27
%33 = call i32 (...) @usage()
br label %34
34: ; preds = %32, %29
ret i32 0
}