#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 */

/* Variables and functions */
int /*<<< orphan*/ error(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int sscanf(char *, char *, int *, int *, int *, int *, int *, int *);
char *convertmac(char *from) {
  int a, b, c, d, e, f;
  static char buf[32];
  if (sscanf(from, "%2x%2x%2x%2x%2x%2x", &a, &b, &c, &d, &e, &f) != 6) {
    error("Bad mac: %s\n", from);
    return (char *)NULL;
  }
  sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", a, b, c, d, e, f);
  return buf;
}


x86 assembly (clang, -O0):
<convertmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
lea    -0x24(%rbp),%r10
lea    -0x28(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     1193 <convertmac+0x63>
mov    -0x10(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1040 <error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ce <convertmac+0x9e>
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x24(%rbp),%r10d
mov    -0x28(%rbp),%eax
lea    0x2ea1(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <sprintf@plt>
lea    0x2e86(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertmac>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0xeb7(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
push   %rax
push   %r10
call   1030 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    11a8 <convertmac+0x78>
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0xc(%rsp),%r10d
mov    0x8(%rsp),%eax
lea    0x2ec0(%rip),%rbx
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1050 <sprintf@plt>
add    $0x10,%rsp
jmp    11b9 <convertmac+0x89>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1040 <error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@convertmac.buf = internal global [32 x i8] zeroinitializer
@.str = [19 x i8] c"%2x%2x%2x%2x%2x%2x\00"
@.str.1 = [13 x i8] c"Bad mac: %s\0A\00"
@.str.2 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @convertmac(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9)
%12 = icmp ne i32 %11, 6
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i8* null, i8** %2
br label %24
16: ; preds = %1
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @convertmac.buf, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 %20, i32 %21, i32 %22)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @convertmac.buf, i64 0, i64 0), i8** %2
br label %24
24: ; preds = %16, %13
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@convertmac.buf = internal global [32 x i8] zeroinitializer
@.str = [19 x i8] c"%2x%2x%2x%2x%2x%2x\00"
@.str.1 = [13 x i8] c"Bad mac: %s\0A\00"
@.str.2 = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
define i8* @convertmac(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7)
%15 = icmp eq i32 %14, 6
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
18: ; preds = %1
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @convertmac.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20, i32 %21, i32 %22, i32 %23, i32 %24)
br label %26
26: ; preds = %18, %16
%27 = phi i8* [ null, %16 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @convertmac.buf, i64 0, i64 0), %18 ]
ret i8* %27
}