#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_3__ {
  int /*<<< orphan*/ *sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
  struct sockaddr ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_2__);
scalar_t__ ioctl(int, int /*<<< orphan*/, 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*/ strcpy(int /*<<< orphan*/, char *);
main(int argc, char *argv[]) {
  int fd;
  union {
    struct sockaddr_in *psa;
    struct sockaddr *pga;
  } ua;
  unsigned char *eap;
  struct ifreq ifreq;
  if (argc < 2)
    exit(0);
  memset(&ifreq, 0, sizeof(struct ifreq));
  ua.pga = &(ifreq.ifr_addr);
  ua.psa->sin_family = AF_INET;
  ua.psa->sin_addr.s_addr = inet_addr(argv[1]);
  fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (fd < 0) {
    perror("socket");
    exit(0);
  }
  strcpy(ifreq.ifr_name, "eth0");
  if (ioctl(fd, SIOCGIFHWADDR, &ifreq) < 0) {
    perror("ioctl");
    exit(0);
  }
  printf("IP address:       %s\n", inet_ntoa(ua.psa->sin_addr));
  eap = (unsigned char *)&(ifreq.ifr_hwaddr.sa_data[0]);
  printf("Ethernet address: %02X:%02X:%02X:%02X:%02X:%02X", eap[0], eap[1],
         eap[2], eap[3], eap[4], eap[5]);
  printf("\n");
  close(fd);
  exit(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)
cmpl   $0x2,-0x8(%rbp)
jge    11c7 <main+0x27>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x38(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x20(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1248 <main+0xa8>
lea    0xdc4(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%edi
lea    0xdb5(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    1289 <main+0xe9>
lea    0xd8f(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    -0x28(%rbp),%rax
movzbl 0x2(%rax),%ecx
mov    -0x28(%rbp),%rax
movzbl 0x3(%rax),%r8d
mov    -0x28(%rbp),%rax
movzbl 0x4(%rax),%r9d
mov    -0x28(%rbp),%rax
movzbl 0x5(%rax),%eax
lea    0xd43(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    12af <main+0xff>
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2e0d(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    (%r14),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    1216 <main+0x66>
lea    0xdec(%rip),%rdi
jmp    1249 <main+0x99>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
lea    0xde4(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1080 <ioctl@plt>
test   %rax,%rax
jns    1255 <main+0xa5>
lea    0xdc3(%rip),%rdi
call   10b0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x14(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xdad(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
movzbl (%rax),%esi
movzbl 0x1(%rax),%edx
movzbl 0x2(%rax),%ecx
movzbl 0x3(%rax),%r8d
movzbl 0x4(%rax),%r9d
movzbl 0x5(%rax),%eax
mov    %eax,(%rsp)
lea    0xd91(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%union.anon = type { %struct.sockaddr_in* }
%struct.sockaddr_in = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.ifreq = type { %struct.TYPE_3__, i32, %struct.sockaddr }
%struct.TYPE_3__ = type { i32* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"eth0\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [22 x i8] c"IP address: %s\0A\00"
@.str.4 = [48 x i8] c"Ethernet address: %02X:%02X:%02X:%02X:%02X:%02X\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %union.anon
%8 = alloca i8*
%9 = alloca %struct.ifreq
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = call i32 @memset(%struct.ifreq* %9, i32 0, i32 16)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %9, i32 0, i32 2
%17 = bitcast %union.anon* %7 to %struct.sockaddr**
store %struct.sockaddr* %16, %struct.sockaddr** %17
%18 = load i32, i32* @AF_INET
%19 = bitcast %union.anon* %7 to %struct.sockaddr_in**
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %19
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 1
store i32 %18, i32* %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @inet_addr(i8* %24)
%26 = bitcast %union.anon* %7 to %struct.sockaddr_in**
%27 = load %struct.sockaddr_in*, %struct.sockaddr_in** %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 0
store i32 %25, i32* %29
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_DGRAM
%32 = load i32, i32* @IPPROTO_UDP
%33 = call i32 @socket(i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %14
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %14
%40 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %9, i32 0, i32 1
%41 = load i32, i32* %40
%42 = call i32 @strcpy(i32 %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = load i32, i32* @SIOCGIFHWADDR
%45 = call i64 @ioctl(i32 %43, i32 %44, %struct.ifreq* %9)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %39
%51 = bitcast %union.anon* %7 to %struct.sockaddr_in**
%52 = load %struct.sockaddr_in*, %struct.sockaddr_in** %51
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %52, i32 0, i32 0
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %9, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 0
%60 = load i32*, i32** %59
%61 = getelementptr inbounds i32, i32* %60, i64 0
%62 = bitcast i32* %61 to i8*
store i8* %62, i8** %8
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i64 0
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i8*, i8** %8
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i64 2
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = load i8*, i8** %8
%76 = getelementptr inbounds i8, i8* %75, i64 3
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = load i8*, i8** %8
%80 = getelementptr inbounds i8, i8* %79, i64 4
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = load i8*, i8** %8
%84 = getelementptr inbounds i8, i8* %83, i64 5
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %66, i32 %70, i32 %74, i32 %78, i32 %82, i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
%91 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_3__, i32, %struct.sockaddr }
%struct.TYPE_3__ = type { i32* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"eth0\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [22 x i8] c"IP address: %s\0A\00"
@.str.4 = [48 x i8] c"Ethernet address: %02X:%02X:%02X:%02X:%02X:%02X\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 16)
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 2
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %10, i64 1, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @inet_addr(i8* %14)
%16 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %10, i64 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = load i32, i32* @IPPROTO_UDP
%20 = call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %8
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %8
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 @strcpy(i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @SIOCGIFHWADDR
%30 = call i64 @ioctl(i32 %20, i32 %29, %struct.ifreq* %3)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %25
%36 = load i32, i32* %16
%37 = call i8* @inet_ntoa(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = bitcast %struct.ifreq* %3 to i8**
%40 = load i8*, i8** %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = getelementptr inbounds i8, i8* %40, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = getelementptr inbounds i8, i8* %40, i64 2
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = getelementptr inbounds i8, i8* %40, i64 3
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = getelementptr inbounds i8, i8* %40, i64 4
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = getelementptr inbounds i8, i8* %40, i64 5
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %42, i32 %45, i32 %48, i32 %51, i32 %54, i32 %57)
%59 = call i32 @putchar(i32 10)
%60 = call i32 @close(i32 %20)
%61 = call i32 @exit(i32 0)
unreachable
}