#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 ifreq {
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ getHWAddrForInterface(char const *, char *, int);
int getopt(int const, char const **, char *);
int linkStatus(int, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int strlen(char const *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ usage(char const *);
int main(const int argc, const char *argv[]) {
  struct ifreq ifr;
  int sd, resultCode = 0;
  int devLen, devLenMax = sizeof(ifr.ifr_name) - 1;
  int argn, opt;
  int opt_usage = 0;
  int opt_link = 0;
  int opt_hwaddr = 0;
  int opt_quiet = 0;
  char *device;
  char hwAddr[19];
  int arg_count = argc;
  while ((opt = getopt(argc, argv, "lahq")) != -1) {
    switch (opt) {
    case 'h':
      opt_usage++;
      arg_count--;
      break;
    case 'q':
      opt_quiet++;
      arg_count--;
      break;
    case 'l':
      opt_link++;
      arg_count--;
      break;
    case 'a':
      opt_hwaddr++;
      arg_count--;
      break;
    }
  }
  if (opt_usage || arg_count <= 0) {
    usage(argv[0]);
    exit(0);
  }
  devLen = strlen(argv[argc - 1]);
  if (devLen > devLenMax) {
    printf(
        "ERROR: Invalid device name (too many characters to be a device!)\n");
    return 1;
  }
  if (opt_link) {
    if (!opt_quiet) {
      printf("%s: ", argv[argc - 1]);
      fflush(stdout);
    }
    memset(&ifr, 0, sizeof(ifr));
    strncpy(ifr.ifr_name, argv[argc - 1], devLenMax);
    if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
      perror("Cannot get control socket");
      resultCode = 1;
    } else {
      switch (linkStatus(sd, &ifr)) {
      case 0:
        printf("ERROR: Something truly weird happened in linkStatus\n");
        resultCode = -1;
        break;
      case 1:
        printf("Link detected\n");
        break;
      case 2:
        printf("WARNING: no link\n");
        resultCode = 1;
        break;
      case 3:
        resultCode = 2;
        break;
      }
    }
  }
  if (opt_hwaddr) {
    hwAddr[18] = '\0';
    if (getHWAddrForInterface(argv[argc - 1], hwAddr, 18) != 0) {
      printf("ERROR: Could not determine hardware address of device '%s'\n",
             argv[argc - 1]);
      exit(1);
    }
    if (opt_quiet) {
      printf("%s\n", hwAddr);
    } else {
      printf("%s: %s\n", argv[argc - 1], hwAddr);
    }
  }
  return resultCode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x3,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     12ad <main+0xed>
mov    -0x30(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0x10,%eax
ja     12a8 <main+0xe8>
mov    -0x70(%rbp),%rax
lea    0xdc8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    12a8 <main+0xe8>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    12a8 <main+0xe8>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    12a8 <main+0xe8>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    1209 <main+0x49>
cmpl   $0x0,-0x34(%rbp)
jne    12c1 <main+0x101>
cmpl   $0x0,-0x64(%rbp)
jg     12d4 <main+0x114>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1313 <main+0x153>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14f3 <main+0x333>
cmpl   $0x0,-0x38(%rbp)
je     1444 <main+0x284>
cmpl   $0x0,-0x40(%rbp)
jne    1354 <main+0x194>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncpy@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    13bd <main+0x1fd>
lea    0xcf4(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    143f <main+0x27f>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1090 <linkStatus@plt>
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0x3,%eax
ja     143a <main+0x27a>
mov    -0x78(%rbp),%rax
lea    0xc1d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    143a <main+0x27a>
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    143a <main+0x27a>
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    143a <main+0x27a>
movl   $0x2,-0x20(%rbp)
jmp    143f <main+0x27f>
jmp    1444 <main+0x284>
cmpl   $0x0,-0x3c(%rbp)
je     14ed <main+0x32d>
movb   $0x0,-0x4e(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x12,%edx
call   1070 <getHWAddrForInterface@plt>
cmp    $0x0,%rax
je     14a4 <main+0x2e4>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x40(%rbp)
je     14c5 <main+0x305>
lea    -0x60(%rbp),%rsi
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14e8 <main+0x328>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x60(%rbp),%rdx
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14ed <main+0x32d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %r15d,%r15d
lea    0xe67(%rip),%rbx
lea    0xe0c(%rip),%r13
movl   $0x0,0xc(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
mov    %edi,%r12d
jmp    1215 <main+0x45>
cmp    $0xffffffff,%eax
je     125e <main+0x8e>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10d0 <getopt@plt>
lea    -0x61(%rax),%ecx
cmp    $0x10,%ecx
ja     1210 <main+0x40>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
addl   $0x1,(%rsp)
add    $0xffffffff,%r12d
jmp    1215 <main+0x45>
add    $0x1,%r15d
add    $0xffffffff,%r12d
jmp    1215 <main+0x45>
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%r12d
jmp    1215 <main+0x45>
addl   $0x1,0x4(%rsp)
add    $0xffffffff,%r12d
jmp    1215 <main+0x45>
test   %r15d,%r15d
jne    1404 <main+0x234>
test   %r12d,%r12d
jle    1404 <main+0x234>
movslq %ebp,%rbx
mov    -0x8(%r14,%rbx,8),%rdi
call   1050 <strlen@plt>
cmp    $0x4,%eax
jl     1298 <main+0xc8>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    13db <main+0x20b>
add    $0xffffffffffffffff,%rbx
cmpl   $0x0,0xc(%rsp)
je     1359 <main+0x189>
mov    0x4(%rsp),%r15d
test   %r15d,%r15d
mov    (%rsp),%r12d
jne    12d5 <main+0x105>
mov    (%r14,%rbx,8),%rsi
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0x8(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    0x8(%rsp),%edi
mov    (%r14,%rbx,8),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     13ec <main+0x21c>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <linkStatus@plt>
cmp    $0x3,%eax
ja     1391 <main+0x1c1>
mov    %eax,%eax
lea    0xd0f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd96(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
test   %r12d,%r12d
jne    1396 <main+0x1c6>
jmp    13db <main+0x20b>
xor    %ebp,%ebp
mov    0x4(%rsp),%r15d
mov    (%rsp),%r12d
test   %r12d,%r12d
jne    1396 <main+0x1c6>
jmp    13db <main+0x20b>
lea    0xd5b(%rip),%rdi
call   1040 <puts@plt>
test   %r12d,%r12d
jne    1396 <main+0x1c6>
jmp    13db <main+0x20b>
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
jmp    13f8 <main+0x228>
mov    $0x2,%ebp
test   %r12d,%r12d
je     13db <main+0x20b>
movb   $0x0,0x22(%rsp)
mov    (%r14,%rbx,8),%rdi
lea    0x10(%rsp),%rsi
mov    $0x12,%edx
call   1080 <getHWAddrForInterface@plt>
test   %rax,%rax
jne    1413 <main+0x243>
test   %r15d,%r15d
je     13c4 <main+0x1f4>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
jmp    13db <main+0x20b>
mov    (%r14,%rbx,8),%rsi
lea    0xce5(%rip),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc6b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
test   %r12d,%r12d
jne    1396 <main+0x1c6>
jmp    13db <main+0x20b>
mov    (%r14),%rdi
call   10b0 <usage@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    (%r14,%rbx,8),%rsi
lea    0xc5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@.str = [5 x i8] c"lahq\00"
@.str.1 = [66 x i8] c"ERROR: Invalid device name (too many characters to be a device!)\0A\00"
@.str.2 = [5 x i8] c"%s: \00"
@stdout = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [26 x i8] c"Cannot get control socket\00"
@.str.4 = [53 x i8] c"ERROR: Something truly weird happened in linkStatus\0A\00"
@.str.5 = [15 x i8] c"Link detected\0A\00"
@.str.6 = [18 x i8] c"WARNING: no link\0A\00"
@.str.7 = [60 x i8] c"ERROR: Could not determine hardware address of device '%s'\0A\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [8 x i8] c"%s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ifreq
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca [19 x i8]
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 3, i32* %10
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
%20 = load i32, i32* %4
store i32 %20, i32* %19
br label %21
21: ; preds = %48, %2
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @getopt(i32 %22, i8** %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %12
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %49
26: ; preds = %21
%27 = load i32, i32* %12
switch i32 %27, label %48 [
i32 104, label %28
i32 113, label %33
i32 108, label %38
i32 97, label %43
]
28: ; preds = %26
%29 = load i32, i32* %13
%30 = add nsw i32 %29, 1
store i32 %30, i32* %13
%31 = load i32, i32* %19
%32 = add nsw i32 %31, -1
store i32 %32, i32* %19
br label %48
33: ; preds = %26
%34 = load i32, i32* %16
%35 = add nsw i32 %34, 1
store i32 %35, i32* %16
%36 = load i32, i32* %19
%37 = add nsw i32 %36, -1
store i32 %37, i32* %19
br label %48
38: ; preds = %26
%39 = load i32, i32* %14
%40 = add nsw i32 %39, 1
store i32 %40, i32* %14
%41 = load i32, i32* %19
%42 = add nsw i32 %41, -1
store i32 %42, i32* %19
br label %48
43: ; preds = %26
%44 = load i32, i32* %15
%45 = add nsw i32 %44, 1
store i32 %45, i32* %15
%46 = load i32, i32* %19
%47 = add nsw i32 %46, -1
store i32 %47, i32* %19
br label %48
48: ; preds = %26, %43, %38, %33, %28
br label %21
49: ; preds = %21
%50 = load i32, i32* %13
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %49
%53 = load i32, i32* %19
%54 = icmp sle i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %52, %49
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @usage(i8* %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %52
%62 = load i8**, i8*** %5
%63 = load i32, i32* %4
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %62, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @strlen(i8* %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = load i32, i32* %10
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %61
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %161
74: ; preds = %61
%75 = load i32, i32* %14
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %120
77: ; preds = %74
%78 = load i32, i32* %16
%79 = icmp ne i32 %78, 0
br i1 %79, label %90, label %80
80: ; preds = %77
%81 = load i8**, i8*** %5
%82 = load i32, i32* %4
%83 = sub nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %81, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %86)
%88 = load i32, i32* @stdout
%89 = call i32 @fflush(i32 %88)
br label %90
90: ; preds = %80, %77
%91 = call i32 @memset(%struct.ifreq* %6, i32 0, i32 4)
%92 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%93 = load i32, i32* %92
%94 = load i8**, i8*** %5
%95 = load i32, i32* %4
%96 = sub nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
%100 = load i32, i32* %10
%101 = call i32 @strncpy(i32 %93, i8* %99, i32 %100)
%102 = load i32, i32* @AF_INET
%103 = load i32, i32* @SOCK_DGRAM
%104 = call i32 @socket(i32 %102, i32 %103, i32 0)
store i32 %104, i32* %7
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %90
%107 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %8
br label %119
108: ; preds = %90
%109 = load i32, i32* %7
%110 = call i32 @linkStatus(i32 %109, %struct.ifreq* %6)
switch i32 %110, label %118 [
i32 0, label %111
i32 1, label %113
i32 2, label %115
i32 3, label %117
]
111: ; preds = %108
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %8
br label %118
113: ; preds = %108
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %118
115: ; preds = %108
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %8
br label %118
117: ; preds = %108
store i32 2, i32* %8
br label %118
118: ; preds = %108, %117, %115, %113, %111
br label %119
119: ; preds = %118, %106
br label %120
120: ; preds = %119, %74
%121 = load i32, i32* %15
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %159
123: ; preds = %120
%124 = getelementptr inbounds [19 x i8], [19 x i8]* %18, i64 0, i64 18
store i8 0, i8* %124
%125 = load i8**, i8*** %5
%126 = load i32, i32* %4
%127 = sub nsw i32 %126, 1
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8*, i8** %125, i64 %128
%130 = load i8*, i8** %129
%131 = getelementptr inbounds [19 x i8], [19 x i8]* %18, i64 0, i64 0
%132 = call i64 @getHWAddrForInterface(i8* %130, i8* %131, i32 18)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %143
134: ; preds = %123
%135 = load i8**, i8*** %5
%136 = load i32, i32* %4
%137 = sub nsw i32 %136, 1
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8*, i8** %135, i64 %138
%140 = load i8*, i8** %139
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i8* %140)
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %123
%144 = load i32, i32* %16
%145 = icmp ne i32 %144, 0
br i1 %145, label %146, label %149
146: ; preds = %143
%147 = getelementptr inbounds [19 x i8], [19 x i8]* %18, i64 0, i64 0
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %147)
br label %158
149: ; preds = %143
%150 = load i8**, i8*** %5
%151 = load i32, i32* %4
%152 = sub nsw i32 %151, 1
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8*, i8** %150, i64 %153
%155 = load i8*, i8** %154
%156 = getelementptr inbounds [19 x i8], [19 x i8]* %18, i64 0, i64 0
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %155, i8* %156)
br label %158
158: ; preds = %149, %146
br label %159
159: ; preds = %158, %120
%160 = load i32, i32* %8
store i32 %160, i32* %3
br label %161
161: ; preds = %159, %72
%162 = load i32, i32* %3
ret i32 %162
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@.str = [5 x i8] c"lahq\00"
@.str.2 = [5 x i8] c"%s: \00"
@stdout = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [26 x i8] c"Cannot get control socket\00"
@.str.7 = [60 x i8] c"ERROR: Could not determine hardware address of device '%s'\0A\00"
@.str.9 = [8 x i8] c"%s: %s\0A\00"
@str = [17 x i8] c"WARNING: no link\00"
@str.10 = [14 x i8] c"Link detected\00"
@str.11 = [52 x i8] c"ERROR: Something truly weird happened in linkStatus\00"
@str.12 = [65 x i8] c"ERROR: Invalid device name (too many characters to be a device!)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.ifreq
%4 = alloca [19 x i8]
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %27, %2
%8 = phi i32 [ %28, %27 ], [ 0, %2 ]
%9 = phi i32 [ %14, %27 ], [ 0, %2 ]
%10 = phi i32 [ %19, %27 ], [ 0, %2 ]
%11 = phi i32 [ %23, %27 ], [ 0, %2 ]
%12 = phi i32 [ %29, %27 ], [ %0, %2 ]
br label %13
13: ; preds = %7, %33
%14 = phi i32 [ %9, %7 ], [ %34, %33 ]
%15 = phi i32 [ %10, %7 ], [ %19, %33 ]
%16 = phi i32 [ %11, %7 ], [ %23, %33 ]
%17 = phi i32 [ %12, %7 ], [ %35, %33 ]
br label %18
18: ; preds = %13, %36
%19 = phi i32 [ %15, %13 ], [ %37, %36 ]
%20 = phi i32 [ %16, %13 ], [ %23, %36 ]
%21 = phi i32 [ %17, %13 ], [ %38, %36 ]
br label %22
22: ; preds = %18, %30
%23 = phi i32 [ %20, %18 ], [ %31, %30 ]
%24 = phi i32 [ %21, %18 ], [ %32, %30 ]
br label %25
25: ; preds = %22, %25
%26 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %26, label %25 [
i32 -1, label %39
i32 104, label %27
i32 113, label %30
i32 108, label %33
i32 97, label %36
]
27: ; preds = %25
%28 = add nuw nsw i32 %8, 1
%29 = add nsw i32 %24, -1
br label %7
30: ; preds = %25
%31 = add nsw i32 %23, 1
%32 = add nsw i32 %24, -1
br label %22
33: ; preds = %25
%34 = add nsw i32 %14, 1
%35 = add nsw i32 %24, -1
br label %13
36: ; preds = %25
%37 = add nsw i32 %19, 1
%38 = add nsw i32 %24, -1
br label %18
39: ; preds = %25
%40 = icmp ne i32 %8, 0
%41 = icmp slt i32 %24, 1
%42 = select i1 %40, i1 true, i1 %41
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i8*, i8** %1
%45 = tail call i32 @usage(i8* %44)
%46 = tail call i32 @exit(i32 0)
unreachable
47: ; preds = %39
%48 = add nsw i32 %0, -1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = load i8*, i8** %50
%52 = tail call i32 @strlen(i8* %51)
%53 = icmp sgt i32 %52, 3
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.12, i64 0, i64 0))
br label %105
56: ; preds = %47
%57 = icmp eq i32 %14, 0
br i1 %57, label %86, label %58
58: ; preds = %56
%59 = icmp eq i32 %23, 0
br i1 %59, label %60, label %65
60: ; preds = %58
%61 = load i8*, i8** %50
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @stdout
%64 = tail call i32 @fflush(i32 %63)
br label %65
65: ; preds = %60, %58
%66 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 4)
%67 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%68 = load i32, i32* %67
%69 = load i8*, i8** %50
%70 = call i32 @strncpy(i32 %68, i8* %69, i32 3)
%71 = load i32, i32* @AF_INET
%72 = load i32, i32* @SOCK_DGRAM
%73 = call i32 @socket(i32 %71, i32 %72, i32 0)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %65
%76 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %86
77: ; preds = %65
%78 = call i32 @linkStatus(i32 %73, %struct.ifreq* %3)
switch i32 %78, label %86 [
i32 0, label %79
i32 1, label %81
i32 2, label %83
i32 3, label %85
]
79: ; preds = %77
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.11, i64 0, i64 0))
br label %86
81: ; preds = %77
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %86
83: ; preds = %77
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %86
85: ; preds = %77
br label %86
86: ; preds = %75, %77, %85, %83, %81, %79, %56
%87 = phi i32 [ 1, %75 ], [ 0, %77 ], [ 2, %85 ], [ 1, %83 ], [ 0, %81 ], [ -1, %79 ], [ 0, %56 ]
%88 = icmp eq i32 %19, 0
br i1 %88, label %105, label %89
89: ; preds = %86
%90 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 18
store i8 0, i8* %90
%91 = load i8*, i8** %50
%92 = call i64 @getHWAddrForInterface(i8* %91, i8* %6, i32 18)
%93 = icmp eq i64 %92, 0
br i1 %93, label %98, label %94
94: ; preds = %89
%95 = load i8*, i8** %50
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %89
%99 = icmp eq i32 %23, 0
br i1 %99, label %102, label %100
100: ; preds = %98
%101 = call i32 @puts(i8* %6)
br label %105
102: ; preds = %98
%103 = load i8*, i8** %50
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %103, i8* %6)
br label %105
105: ; preds = %86, %102, %100, %54
%106 = phi i32 [ 1, %54 ], [ %87, %100 ], [ %87, %102 ], [ %87, %86 ]
ret i32 %106
}