#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int formatMAC(char *unformattedMAC, char *formattedMAC) {
  char tempbuf[3] = "";
  char delims[] = ":";
  char *token = NULL;
  token = strtok(unformattedMAC, delims);
  while (token != NULL) {
    if (strlen(token) == 1) {
      strcpy(tempbuf, "0");
      strcat(tempbuf, token);
      strcat(formattedMAC, tempbuf);
    } else {
      strcat(formattedMAC, token);
    }
    token = strtok(NULL, delims);
    if (token) {
      strcat(formattedMAC, delims);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<formatMAC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
mov    0xe89(%rip),%ax
mov    %ax,-0x15(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     121b <formatMAC+0xcb>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11e0 <formatMAC+0x90>
lea    -0x13(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x13(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11ed <formatMAC+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x15(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1216 <formatMAC+0xc6>
mov    -0x10(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   1070 <strcat@plt>
jmp    1194 <formatMAC+0x44>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatMAC>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r13
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
movw   $0x3a,0xa(%rsp)
lea    0xa(%rsp),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11e0 <formatMAC+0xa0>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
lea    0xe7f(%rip),%r15
lea    0xa(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11b6 <formatMAC+0x76>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %r14,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11e0 <formatMAC+0xa0>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
jmp    1190 <formatMAC+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.formatMAC.delims = [2 x i8] c":\00"
@.str = [2 x i8] c"0\00"
define i32 @formatMAC(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca [2 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = bitcast [3 x i8]* %5 to i8*
%9 = bitcast [2 x i8]* %6 to i8*
store i8* null, i8** %7
%10 = load i8*, i8** %3
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%12 = call i8* @strtok(i8* %10, i8* %11)
store i8* %12, i8** %7
br label %13
13: ; preds = %42, %2
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %7
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%28 = call i32 @strcat(i8* %26, i8* %27)
br label %33
29: ; preds = %16
%30 = load i8*, i8** %4
%31 = load i8*, i8** %7
%32 = call i32 @strcat(i8* %30, i8* %31)
br label %33
33: ; preds = %29, %20
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%35 = call i8* @strtok(i8* null, i8* %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%41 = call i32 @strcat(i8* %39, i8* %40)
br label %42
42: ; preds = %38, %33
br label %13
43: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define i32 @formatMAC(i8* %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = bitcast i16* %4 to i8*
store i16 58, i16* %4
%7 = call i8* @strtok(i8* %0, i8* %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %2, %21
%10 = phi i8* [ %19, %21 ], [ %7, %2 ]
%11 = call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @strcat(i8* %5, i8* %10)
br label %16
16: ; preds = %9, %13
%17 = phi i8* [ %5, %13 ], [ %10, %9 ]
%18 = call i32 @strcat(i8* %1, i8* %17)
%19 = call i8* @strtok(i8* null, i8* %6)
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @strcat(i8* %1, i8* %6)
br label %9
23: ; preds = %16, %2
ret i32 0
}