#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 socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, ...);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int get_all_macs(char **result) {
  struct ifreq ifreq;
  int sock;
  int i;
  for (i = 0; i < 10; i++) {
    char *eth = "";
    sock = socket(AF_INET, SOCK_STREAM, 0);
    sprintf(eth, "eth%d", i);
    strcpy(ifreq.ifr_name, eth);
    if (ioctl(sock, SIOCGIFHWADDR, &ifreq) < 0) {
      continue;
    }
    sprintf(*(result + i * sizeof(char)), "%02x:%02x:%02x:%02x:%02x:%02x",
            (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):
<get_all_macs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    1246 <get_all_macs+0x106>
lea    0xea1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%eax
lea    0xe6e(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11cc <get_all_macs+0x8c>
jmp    1238 <get_all_macs+0xf8>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x0,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movzbl %al,%ecx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movzbl %al,%r8d
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movzbl %al,%r9d
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
movzbl %al,%r10d
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
movzbl %al,%eax
lea    0xde0(%rip),%rsi
movzbl %dl,%edx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1153 <get_all_macs+0x13>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_all_macs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xead(%rip),%r15
lea    0x8(%rsp),%r12
xor    %r13d,%r13d
jmp    117e <get_all_macs+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r13
cmp    $0xa,%r13
je     120d <get_all_macs+0xcd>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
movzbl %r13b,%edx
mov    %r15,%rdi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    0x10(%rsp),%edi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1170 <get_all_macs+0x30>
mov    (%r14,%r13,8),%rdi
mov    0x8(%rsp),%rax
movzbl (%rax),%edx
movzbl 0x8(%rax),%ecx
movzbl 0x10(%rax),%r8d
movzbl 0x18(%rax),%r9d
movzbl 0x20(%rax),%ebp
movzbl 0x28(%rax),%ebx
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
push   %rbx
push   %rbp
call   1050 <sprintf@plt>
add    $0x10,%rsp
jmp    1170 <get_all_macs+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64* }
@.str = [1 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [6 x i8] c"eth%d\00"
@SIOCGIFHWADDR = global i32 0
@.str.2 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i32 @get_all_macs(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.ifreq
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %2
store i32 0, i32* %5
br label %7
7: ; preds = %76, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %79
10: ; preds = %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %4
%14 = load i8*, i8** %6
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %16)
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i8*, i8** %6
%21 = call i32 @strcpy(i32 %19, i8* %20)
%22 = load i32, i32* %4
%23 = load i32, i32* @SIOCGIFHWADDR
%24 = call i64 @ioctl(i32 %22, i32 %23, %struct.ifreq* %3)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %10
br label %76
27: ; preds = %10
%28 = load i8**, i8*** %2
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 1
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i64*, i64** %35
%37 = getelementptr inbounds i64, i64* %36, i64 0
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i8
%40 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, 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* %3, 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* %3, 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* %3, 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* %3, 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*, i8*, i8, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %39, i32 %46, i32 %53, i32 %60, i32 %67, i32 %74)
br label %76
76: ; preds = %27, %26
%77 = load i32, i32* %5
%78 = add nsw i32 %77, 1
store i32 %78, i32* %5
br label %7
79: ; preds = %7
ret i32 0
}

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