#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 */
typedef int u_char;

/* Variables and functions */
int get_mac(char const *, int *);
int /*<<< orphan*/ sprintf(int *, char *, int, int, int, int, int, int);
int get_format_mac(const char *device_name, u_char *addr) {
  int stat;
  u_char addr_buffer[6];
  stat = get_mac(device_name, addr_buffer);
  if (stat == 0) {
    sprintf(addr, "%02x:%02x:%02x:%02x:%02x:%02x", addr_buffer[0],
            addr_buffer[1], addr_buffer[2], addr_buffer[3], addr_buffer[4],
            addr_buffer[5]);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_format_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <get_mac@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1183 <get_format_mac+0x63>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x34(%rbp),%r9d
mov    -0x30(%rbp),%r10d
mov    -0x2c(%rbp),%eax
lea    0xe96(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    118a <get_format_mac+0x6a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_format_mac>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rsp,%rsi
call   1030 <get_mac@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    116d <get_format_mac+0x4d>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x10(%rsp),%r10d
mov    0x14(%rsp),%eax
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1040 <sprintf@plt>
add    $0x10,%rsp
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i32 @get_format_mac(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [6 x i32]
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%10 = call i32 @get_mac(i8* %8, i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 4
%24 = load i32, i32* %23
%25 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 5
%26 = load i32, i32* %25
%27 = call i32 @sprintf(i32* %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %20, i32 %22, i32 %24, i32 %26)
store i32 0, i32* %3
br label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %29
29: ; preds = %28, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i32 @get_format_mac(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%6 = call i32 @get_mac(i8* %0, i32* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %2
%9 = load i32, i32* %5
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%19 = load i32, i32* %18
%20 = call i32 @sprintf(i32* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19)
br label %21
21: ; preds = %2, %8
%22 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %22
}