#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 /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_STREAM;
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*/ strcpy(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  struct ifreq ifreq;
  int sock;
  if (argc != 2) {
    printf("Usage : ethname\n");
    return 1;
  }
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket.......");
    return 2;
  }
  strcpy(ifreq.ifr_name, argv[1]);
  if (ioctl(sock, SIOCGIFHWADDR, &ifreq) < 0) {
    perror("ioctl.......");
    return 3;
  }
  printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
         (unsigned char)ifreq.ifr_hwaddr.sa_data[0],
         (unsigned char)ifreq.ifr_hwaddr.sa_data[1],
         (unsigned char)ifreq.ifr_hwaddr.sa_data[2],
         (unsigned char)ifreq.ifr_hwaddr.sa_data[3],
         (unsigned char)ifreq.ifr_hwaddr.sa_data[4],
         (unsigned char)ifreq.ifr_hwaddr.sa_data[5]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1269 <main+0x119>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11c7 <main+0x77>
lea    0xe5b(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1269 <main+0x119>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    120e <main+0xbe>
lea    0xe22(%rip),%rdi
call   1060 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1269 <main+0x119>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movzbl %al,%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movzbl %al,%edx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
movzbl %al,%r8d
mov    -0x20(%rbp),%rax
mov    0x20(%rax),%rax
movzbl %al,%r9d
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%rax
movzbl %al,%eax
lea    0xdd4(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11e3 <main+0x83>
mov    %rsi,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11fd <main+0x9d>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
call   1030 <strcpy@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
js     1210 <main+0xb0>
mov    0x8(%rsp),%rax
movzbl (%rax),%esi
movzbl 0x8(%rax),%edx
movzbl 0x10(%rax),%ecx
movzbl 0x18(%rax),%r8d
movzbl 0x20(%rax),%r9d
movzbl 0x28(%rax),%eax
mov    %eax,(%rsp)
lea    0xe43(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f4 <main+0x94>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%ebx
jmp    11f4 <main+0x94>
lea    0xdf7(%rip),%rdi
call   1070 <perror@plt>
mov    $0x3,%ebx
jmp    11f4 <main+0x94>

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@.str = [17 x i8] c"Usage : ethname\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"socket.......\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [13 x i8] c"ioctl.......\00"
@.str.3 = [31 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %76
12: ; preds = %2
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %76
19: ; preds = %12
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i32 %21, i8* %24)
%26 = load i32, i32* %7
%27 = load i32, i32* @SIOCGIFHWADDR
%28 = call i64 @ioctl(i32 %26, i32 %27, %struct.ifreq* %6)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %76
32: ; preds = %19
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i64*, i64** %34
%36 = getelementptr inbounds i64, i64* %35, i64 0
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i8
%39 = zext i8 %38 to i32
%40 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
%42 = load i64*, i64** %41
%43 = getelementptr inbounds i64, i64* %42, i64 1
%44 = load i64, i64* %43
%45 = trunc i64 %44 to i8
%46 = zext i8 %45 to i32
%47 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i64*, i64** %48
%50 = getelementptr inbounds i64, i64* %49, i64 2
%51 = load i64, i64* %50
%52 = trunc i64 %51 to i8
%53 = zext i8 %52 to i32
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
%56 = load i64*, i64** %55
%57 = getelementptr inbounds i64, i64* %56, i64 3
%58 = load i64, i64* %57
%59 = trunc i64 %58 to i8
%60 = zext i8 %59 to i32
%61 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%62 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %61, i32 0, i32 0
%63 = load i64*, i64** %62
%64 = getelementptr inbounds i64, i64* %63, i64 4
%65 = load i64, i64* %64
%66 = trunc i64 %65 to i8
%67 = zext i8 %66 to i32
%68 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
%70 = load i64*, i64** %69
%71 = getelementptr inbounds i64, i64* %70, i64 5
%72 = load i64, i64* %71
%73 = trunc i64 %72 to i8
%74 = zext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %46, i32 %53, i32 %60, i32 %67, i32 %74)
store i32 0, i32* %3
br label %76
76: ; preds = %32, %30, %17, %10
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"socket.......\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [13 x i8] c"ioctl.......\00"
@.str.3 = [31 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@str = [16 x i8] c"Usage : ethname\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %51
8: ; preds = %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %51
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @strcpy(i32 undef, i8* %17)
%19 = load i32, i32* @SIOCGIFHWADDR
%20 = call i64 @ioctl(i32 %11, i32 %19, %struct.ifreq* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %51
24: ; preds = %15
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
%26 = load i64*, i64** %25
%27 = load i64, i64* %26
%28 = trunc i64 %27 to i32
%29 = and i32 %28, 255
%30 = getelementptr inbounds i64, i64* %26, i64 1
%31 = load i64, i64* %30
%32 = trunc i64 %31 to i32
%33 = and i32 %32, 255
%34 = getelementptr inbounds i64, i64* %26, i64 2
%35 = load i64, i64* %34
%36 = trunc i64 %35 to i32
%37 = and i32 %36, 255
%38 = getelementptr inbounds i64, i64* %26, i64 3
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i32
%41 = and i32 %40, 255
%42 = getelementptr inbounds i64, i64* %26, i64 4
%43 = load i64, i64* %42
%44 = trunc i64 %43 to i32
%45 = and i32 %44, 255
%46 = getelementptr inbounds i64, i64* %26, i64 5
%47 = load i64, i64* %46
%48 = trunc i64 %47 to i32
%49 = and i32 %48, 255
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %33, i32 %37, i32 %41, i32 %45, i32 %49)
br label %51
51: ; preds = %24, %22, %13, %6
%52 = phi i32 [ 1, %6 ], [ 2, %13 ], [ 3, %22 ], [ 0, %24 ]
ret i32 %52
}