#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ *sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int ETH_ALEN;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char, unsigned char,
                           unsigned char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strupr(char *);
int main(int argc, char **argv) {
  int fd;
  int upper = 0;
  struct ifreq ifr;
  char mac[ETH_ALEN * 2 + 5];
  char *dev;
  if (argc > 3) {
    printf("getmac"
           " [-u | --upper-case] [-h | --help] <device>"
           "\n");
    exit(1);
  }
  if (argc == 2) {
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
      printf("getmac"
             " [-u | --upper-case] [-h | --help] <device>"
             "\n"
             "getmac"
             "-"
             "1.0"
             " - small app (~9K) to print device mac address"
             "\n-u|--upper-case\tUppercase MAC address string"
             "\n-h|--help\tHelp menu\n");
      return 0;
    }
    if (strcmp(argv[1], "-u") == 0 || strcmp(argv[1], "--upper-case") == 0) {
      printf("getmac"
             " [-u | --upper-case] [-h | --help] <device>"
             "\n");
      exit(1);
    }
    dev = (char *)argv[1];
  }
  if (argc == 3) {
    if (strcmp(argv[1], "-u") == 0 || strcmp(argv[1], "--upper-case") == 0) {
      upper = 1;
      dev = (char *)argv[2];
    } else {
      printf("getmac"
             " [-u | --upper-case] [-h | --help] <device>"
             "\n");
      exit(1);
    }
  }
  fd = socket(PF_INET, SOCK_DGRAM, 0);
  strcpy(ifr.ifr_name, dev);
  if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
    close(fd);
    perror("ioctl[SIOCGIFHWADDR]");
    exit(1);
  }
  sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
          (unsigned char)ifr.ifr_hwaddr.sa_data[0],
          (unsigned char)ifr.ifr_hwaddr.sa_data[1],
          (unsigned char)ifr.ifr_hwaddr.sa_data[2],
          (unsigned char)ifr.ifr_hwaddr.sa_data[3],
          (unsigned char)ifr.ifr_hwaddr.sa_data[4],
          (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
  if (upper)
    printf("%s\n", strupr(mac));
  else
    printf("%s\n", mac);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x5(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1211 <main+0x71>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    12d8 <main+0x138>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe09(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1257 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1278 <main+0xd8>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    147a <main+0x2da>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12b4 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe48(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12cc <main+0x12c>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1353 <main+0x1b3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     131e <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1336 <main+0x196>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    134e <main+0x1ae>
lea    0xcc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1353 <main+0x1b3>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    13b8 <main+0x218>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd51(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %al,%r8b
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %al,%r9b
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%rax
mov    %al,%r10b
mov    -0x28(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xd10(%rip),%rsi
sub    $0x10,%rsp
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r10b,%r10d
mov    %r10d,(%rsp)
movzbl %al,%eax
mov    %eax,0x8(%rsp)
call   10a0 <sprintf@plt>
add    $0x10,%rsp
cmpl   $0x0,-0x18(%rbp)
je     1452 <main+0x2b2>
mov    -0x50(%rbp),%rdi
call   1080 <strupr@plt>
mov    %rax,%rsi
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1464 <main+0x2c4>
mov    -0x50(%rbp),%rsi
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%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
sub    $0x18,%rsp
mov    %rsp,%rbx
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
add    $0x5,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x4,%edi
jge    1357 <main+0x1b7>
mov    %rsi,%r14
cmp    $0x3,%edi
je     125b <main+0xbb>
cmp    $0x2,%edi
jne    1299 <main+0xf9>
mov    0x8(%r14),%rdi
lea    0xe08(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1337 <main+0x197>
add    $0x8,%r14
mov    (%r14),%rdi
lea    0xdef(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1337 <main+0x197>
mov    (%r14),%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1357 <main+0x1b7>
mov    (%r14),%rdi
lea    0xdc9(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1357 <main+0x1b7>
mov    %rbx,-0x30(%rbp)
xor    %r13d,%r13d
jmp    1294 <main+0xf4>
mov    0x8(%r14),%rdi
lea    0xda4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1289 <main+0xe9>
mov    0x8(%r14),%rdi
lea    0xd92(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1357 <main+0x1b7>
mov    %rbx,-0x30(%rbp)
add    $0x10,%r14
mov    $0x1,%r13b
mov    (%r14),%r15
jmp    12a0 <main+0x100>
mov    %rbx,-0x30(%rbp)
xor    %r13d,%r13d
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r14d
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
mov    %r14d,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
js     136d <main+0x1cd>
mov    -0x40(%rbp),%rax
movzbl (%rax),%edx
movzbl 0x8(%rax),%ecx
movzbl 0x10(%rax),%r8d
movzbl 0x18(%rax),%r9d
movzbl 0x20(%rax),%ebx
movzbl 0x28(%rax),%eax
lea    0xd29(%rip),%rsi
mov    %r12,%rdi
push   %rax
push   %rbx
call   10a0 <sprintf@plt>
add    $0x10,%rsp
test   %r13b,%r13b
mov    -0x30(%rbp),%rbx
mov    %r12,%rdi
je     1328 <main+0x188>
call   1080 <strupr@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1060 <close@plt>
jmp    1343 <main+0x1a3>
lea    0xd0f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xc9e(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@ETH_ALEN = global i32 0
@.str = [51 x i8] c"getmac [-u | --upper-case] [-h | --help] <device>\0A\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [173 x i8] c"getmac [-u | --upper-case] [-h | --help] <device>\0Agetmac-1.0 - small app (~9K) to print device mac address\0A-u|--upper-case\09Uppercase MAC address string\0A-h|--help\09Help menu\0A\00"
@.str.4 = [3 x i8] c"-u\00"
@.str.5 = [13 x i8] c"--upper-case\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.6 = [21 x i8] c"ioctl[SIOCGIFHWADDR]\00"
@.str.7 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ifreq
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%13 = load i32, i32* @ETH_ALEN
%14 = mul nsw i32 %13, 2
%15 = add nsw i32 %14, 5
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 3
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %60
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %27
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33, %27
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
store i32 1, i32* %12
br label %148
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %41
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47, %41
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %47
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
store i8* %59, i8** %11
br label %60
60: ; preds = %56, %24
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, 3
br i1 %62, label %63, label %83
63: ; preds = %60
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %75, label %69
69: ; preds = %63
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = call i64 @strcmp(i8* %72, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %69, %63
store i32 1, i32* %7
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
store i8* %78, i8** %11
br label %82
79: ; preds = %69
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %75
br label %83
83: ; preds = %82, %60
%84 = load i32, i32* @PF_INET
%85 = load i32, i32* @SOCK_DGRAM
%86 = call i32 @socket(i32 %84, i32 %85, i32 0)
store i32 %86, i32* %6
%87 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%88 = load i32, i32* %87
%89 = load i8*, i8** %11
%90 = call i32 @strcpy(i32 %88, i8* %89)
%91 = load i32, i32* %6
%92 = load i32, i32* @SIOCGIFHWADDR
%93 = call i64 @ioctl(i32 %91, i32 %92, %struct.ifreq* %8)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %100
95: ; preds = %83
%96 = load i32, i32* %6
%97 = call i32 @close(i32 %96)
%98 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %83
%101 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%102 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %101, i32 0, i32 0
%103 = load i64*, i64** %102
%104 = getelementptr inbounds i64, i64* %103, i64 0
%105 = load i64, i64* %104
%106 = trunc i64 %105 to i8
%107 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%108 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %107, i32 0, i32 0
%109 = load i64*, i64** %108
%110 = getelementptr inbounds i64, i64* %109, i64 1
%111 = load i64, i64* %110
%112 = trunc i64 %111 to i8
%113 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%114 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %113, i32 0, i32 0
%115 = load i64*, i64** %114
%116 = getelementptr inbounds i64, i64* %115, i64 2
%117 = load i64, i64* %116
%118 = trunc i64 %117 to i8
%119 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%120 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %119, i32 0, i32 0
%121 = load i64*, i64** %120
%122 = getelementptr inbounds i64, i64* %121, i64 3
%123 = load i64, i64* %122
%124 = trunc i64 %123 to i8
%125 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%126 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %125, i32 0, i32 0
%127 = load i64*, i64** %126
%128 = getelementptr inbounds i64, i64* %127, i64 4
%129 = load i64, i64* %128
%130 = trunc i64 %129 to i8
%131 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%132 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %131, i32 0, i32 0
%133 = load i64*, i64** %132
%134 = getelementptr inbounds i64, i64* %133, i64 5
%135 = load i64, i64* %134
%136 = trunc i64 %135 to i8
%137 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8 zeroext %106, i8 zeroext %112, i8 zeroext %118, i8 zeroext %124, i8 zeroext %130, i8 zeroext %136)
%138 = load i32, i32* %7
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %100
%141 = call i8* @strupr(i8* %18)
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %141)
br label %145
143: ; preds = %100
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %18)
br label %145
145: ; preds = %143, %140
%146 = load i32, i32* %6
%147 = call i32 @close(i32 %146)
store i32 0, i32* %3
store i32 1, i32* %12
br label %148
148: ; preds = %145, %39
%149 = load i8*, i8** %9
%150 = load i32, i32* %3
ret i32 %150
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@ETH_ALEN = global i32 0
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.4 = [3 x i8] c"-u\00"
@.str.5 = [13 x i8] c"--upper-case\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.6 = [21 x i8] c"ioctl[SIOCGIFHWADDR]\00"
@.str.7 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@str.10 = [172 x i8] c"getmac [-u | --upper-case] [-h | --help] <device>\0Agetmac-1.0 - small app (~9K) to print device mac address\0A-u|--upper-case\09Uppercase MAC address string\0A-h|--help\09Help menu\00"
@str.11 = [50 x i8] c"getmac [-u | --upper-case] [-h | --help] <device>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @ETH_ALEN
%6 = shl nsw i32 %5, 1
%7 = add nsw i32 %6, 5
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = icmp sgt i32 %0, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.11, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
switch i32 %0, label %56 [
i32 2, label %16
i32 3, label %38
]
16: ; preds = %15
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21, %16
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([172 x i8], [172 x i8]* @str.10, i64 0, i64 0))
br label %98
27: ; preds = %21
%28 = load i8*, i8** %17
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %17
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %52
35: ; preds = %31, %27
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.11, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %15
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = tail call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = load i8*, i8** %39
%45 = tail call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43, %38
%48 = getelementptr inbounds i8*, i8** %1, i64 2
br label %52
49: ; preds = %43
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.11, i64 0, i64 0))
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %31, %47
%53 = phi i8** [ %48, %47 ], [ %17, %31 ]
%54 = phi i1 [ true, %47 ], [ false, %31 ]
%55 = load i8*, i8** %53
br label %56
56: ; preds = %52, %15
%57 = phi i1 [ false, %15 ], [ %54, %52 ]
%58 = phi i8* [ undef, %15 ], [ %55, %52 ]
%59 = load i32, i32* @PF_INET
%60 = load i32, i32* @SOCK_DGRAM
%61 = tail call i32 @socket(i32 %59, i32 %60, i32 0)
%62 = tail call i32 @strcpy(i32 undef, i8* %58)
%63 = load i32, i32* @SIOCGIFHWADDR
%64 = call i64 @ioctl(i32 %61, i32 %63, %struct.ifreq* %3)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %56
%67 = call i32 @close(i32 %61)
%68 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %56
%71 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%72 = load i64*, i64** %71
%73 = load i64, i64* %72
%74 = trunc i64 %73 to i8
%75 = getelementptr inbounds i64, i64* %72, i64 1
%76 = load i64, i64* %75
%77 = trunc i64 %76 to i8
%78 = getelementptr inbounds i64, i64* %72, i64 2
%79 = load i64, i64* %78
%80 = trunc i64 %79 to i8
%81 = getelementptr inbounds i64, i64* %72, i64 3
%82 = load i64, i64* %81
%83 = trunc i64 %82 to i8
%84 = getelementptr inbounds i64, i64* %72, i64 4
%85 = load i64, i64* %84
%86 = trunc i64 %85 to i8
%87 = getelementptr inbounds i64, i64* %72, i64 5
%88 = load i64, i64* %87
%89 = trunc i64 %88 to i8
%90 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8 zeroext %74, i8 zeroext %77, i8 zeroext %80, i8 zeroext %83, i8 zeroext %86, i8 zeroext %89)
br i1 %57, label %91, label %94
91: ; preds = %70
%92 = call i8* @strupr(i8* %10)
%93 = call i32 @puts(i8* dereferenceable(1) %92)
br label %96
94: ; preds = %70
%95 = call i32 @puts(i8* %10)
br label %96
96: ; preds = %94, %91
%97 = call i32 @close(i32 %61)
br label %98
98: ; preds = %96, %25
ret i32 0
}