#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 */
struct cli {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, ...);
int /*<<< orphan*/ cli_send(struct cli *, char *, scalar_t__);
int /*<<< orphan*/ free(char *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
scalar_t__ strlen(char *);
int _set_macaddr(struct cli *cli, int argc, char *argv[]) {
  if (argc <= 0) {
    {
      char *__tmp;
      asprintf(&__tmp, "> "
                       "argc <= 0 is invalid"
                       "\n\r");
      cli_send(cli, __tmp, strlen(__tmp) + 1);
      free(__tmp);
    };
    return (-1);
  }
  {
    char *__tmp;
    asprintf(&__tmp,
             "argc = %d, argv[0] = %s"
             "\n\r",
             argc, argv[0]);
    cli_send(cli, __tmp, strlen(__tmp) + 1);
    free(__tmp);
  };
  unsigned int mac[6];
  int num = sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2],
                   &mac[3], &mac[4], &mac[5]);
  if (num != 6) {
    {
      char *__tmp;
      asprintf(&__tmp,
               "> "
               "sscanf failed, num = %d"
               "\n\r",
               num);
      cli_send(cli, __tmp, strlen(__tmp) + 1);
      free(__tmp);
    };
    return (-1);
  }
  {
    char *__tmp;
    asprintf(&__tmp,
             "mac addr = %x %x %x %x %x %x"
             "\n\r",
             mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    cli_send(cli, __tmp, strlen(__tmp) + 1);
    free(__tmp);
  };
  return (0);
}


x86 assembly (clang, -O0):
<_set_macaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11c4 <_set_macaddr+0x74>
lea    -0x28(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <cli_send@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134c <_set_macaddr+0x1fc>
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    -0x30(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <cli_send@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x50(%rbp),%rcx
add    $0x4,%rcx
lea    -0x50(%rbp),%r8
add    $0x8,%r8
lea    -0x50(%rbp),%r9
add    $0xc,%r9
lea    -0x50(%rbp),%r10
add    $0x10,%r10
lea    -0x50(%rbp),%rax
add    $0x14,%rax
lea    0xddd(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x6,-0x54(%rbp)
je     12d4 <_set_macaddr+0x184>
mov    -0x54(%rbp),%edx
lea    -0x60(%rbp),%rdi
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    -0x90(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <cli_send@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134c <_set_macaddr+0x1fc>
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x44(%rbp),%r9d
mov    -0x40(%rbp),%r10d
mov    -0x3c(%rbp),%eax
lea    -0x68(%rbp),%rdi
lea    0xd6d(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1060 <asprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <cli_send@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_set_macaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
test   %esi,%esi
jle    1239 <_set_macaddr+0xe9>
mov    %rdx,%rbx
mov    %esi,%edx
mov    (%rbx),%rcx
lea    0xea5(%rip),%rsi
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %eax,%eax
call   1060 <asprintf@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1070 <cli_send@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    (%rbx),%rdi
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%rax
lea    0x14(%rsp),%rbp
lea    0xe6b(%rip),%rsi
mov    %rsp,%rdx
push   %rbp
push   %rax
call   1050 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    126b <_set_macaddr+0x11b>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x10(%rsp),%ebp
mov    0x14(%rsp),%ebx
lea    0xe62(%rip),%rsi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
push   %rbx
push   %rbp
call   1060 <asprintf@plt>
add    $0x10,%rsp
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <cli_send@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
jmp    12ac <_set_macaddr+0x15c>
lea    0xdc0(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1060 <asprintf@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <cli_send@plt>
mov    (%rsp),%rdi
jmp    12a1 <_set_macaddr+0x151>
lea    0xdd3(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <asprintf@plt>
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <cli_send@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cli = type { i32 }
@.str = [25 x i8] c"> argc <= 0 is invalid\0A\0D\00"
@.str.1 = [26 x i8] c"argc = %d, argv[0] = %s\0A\0D\00"
@.str.2 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.3 = [28 x i8] c"> sscanf failed, num = %d\0A\0D\00"
@.str.4 = [31 x i8] c"mac addr = %x %x %x %x %x %x\0A\0D\00"
define i32 @_set_macaddr(%struct.cli* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.cli*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [6 x i32]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store %struct.cli* %0, %struct.cli** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = call i32 (i8**, i8*, ...) @asprintf(i8** %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%18 = load %struct.cli*, %struct.cli** %5
%19 = load i8*, i8** %8
%20 = load i8*, i8** %8
%21 = call i64 @strlen(i8* %20)
%22 = add nsw i64 %21, 1
%23 = call i32 @cli_send(%struct.cli* %18, i8* %19, i64 %22)
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
store i32 -1, i32* %4
br label %85
26: ; preds = %3
%27 = load i32, i32* %6
%28 = load i8**, i8*** %7
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8**, i8*, ...) @asprintf(i8** %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %30)
%32 = load %struct.cli*, %struct.cli** %5
%33 = load i8*, i8** %9
%34 = load i8*, i8** %9
%35 = call i64 @strlen(i8* %34)
%36 = add nsw i64 %35, 1
%37 = call i32 @cli_send(%struct.cli* %32, i8* %33, i64 %36)
%38 = load i8*, i8** %9
%39 = call i32 @free(i8* %38)
%40 = load i8**, i8*** %7
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 0
%44 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 1
%45 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 2
%46 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 3
%47 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 4
%48 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 5
%49 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %43, i32* %44, i32* %45, i32* %46, i32* %47, i32* %48)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 6
br i1 %51, label %52, label %63
52: ; preds = %26
%53 = load i32, i32* %11
%54 = call i32 (i8**, i8*, ...) @asprintf(i8** %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load %struct.cli*, %struct.cli** %5
%56 = load i8*, i8** %12
%57 = load i8*, i8** %12
%58 = call i64 @strlen(i8* %57)
%59 = add nsw i64 %58, 1
%60 = call i32 @cli_send(%struct.cli* %55, i8* %56, i64 %59)
%61 = load i8*, i8** %12
%62 = call i32 @free(i8* %61)
store i32 -1, i32* %4
br label %85
63: ; preds = %26
%64 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 0
%65 = load i32, i32* %64
%66 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 2
%69 = load i32, i32* %68
%70 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 3
%71 = load i32, i32* %70
%72 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 4
%73 = load i32, i32* %72
%74 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 0, i64 5
%75 = load i32, i32* %74
%76 = call i32 (i8**, i8*, ...) @asprintf(i8** %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %65, i32 %67, i32 %69, i32 %71, i32 %73, i32 %75)
%77 = load %struct.cli*, %struct.cli** %5
%78 = load i8*, i8** %13
%79 = load i8*, i8** %13
%80 = call i64 @strlen(i8* %79)
%81 = add nsw i64 %80, 1
%82 = call i32 @cli_send(%struct.cli* %77, i8* %78, i64 %81)
%83 = load i8*, i8** %13
%84 = call i32 @free(i8* %83)
store i32 0, i32* %4
br label %85
85: ; preds = %63, %52, %16
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
%struct.cli = type { i32 }
@.str = [25 x i8] c"> argc <= 0 is invalid\0A\0D\00"
@.str.1 = [26 x i8] c"argc = %d, argv[0] = %s\0A\0D\00"
@.str.2 = [18 x i8] c"%x:%x:%x:%x:%x:%x\00"
@.str.3 = [28 x i8] c"> sscanf failed, num = %d\0A\0D\00"
@.str.4 = [31 x i8] c"mac addr = %x %x %x %x %x %x\0A\0D\00"
define i32 @_set_macaddr(%struct.cli* %0, i32 %1, i8** nocapture %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [6 x i32]
%7 = alloca i8*
%8 = alloca i8*
%9 = icmp slt i32 %1, 1
br i1 %9, label %10, label %19
10: ; preds = %3
%11 = bitcast i8** %4 to i8*
%12 = call i32 (i8**, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* dereferenceable(1) %13)
%15 = add nsw i64 %14, 1
%16 = call i32 @cli_send(%struct.cli* %0, i8* %13, i64 %15)
%17 = load i8*, i8** %4
%18 = call i32 @free(i8* %17)
br label %65
19: ; preds = %3
%20 = bitcast i8** %5 to i8*
%21 = load i8*, i8** %2
%22 = call i32 (i8**, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %21)
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* dereferenceable(1) %23)
%25 = add nsw i64 %24, 1
%26 = call i32 @cli_send(%struct.cli* %0, i8* %23, i64 %25)
%27 = load i8*, i8** %5
%28 = call i32 @free(i8* %27)
%29 = bitcast [6 x i32]* %6 to i8*
%30 = load i8*, i8** %2
%31 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%32 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 1
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 2
%34 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 3
%35 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 4
%36 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 5
%37 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %31, i32* %32, i32* %33, i32* %34, i32* %35, i32* %36)
%38 = icmp eq i32 %37, 6
br i1 %38, label %48, label %39
39: ; preds = %19
%40 = bitcast i8** %7 to i8*
%41 = call i32 (i8**, i8*, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%42 = load i8*, i8** %7
%43 = call i64 @strlen(i8* dereferenceable(1) %42)
%44 = add nsw i64 %43, 1
%45 = call i32 @cli_send(%struct.cli* %0, i8* %42, i64 %44)
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
br label %63
48: ; preds = %19
%49 = bitcast i8** %8 to i8*
%50 = load i32, i32* %31
%51 = load i32, i32* %32
%52 = load i32, i32* %33
%53 = load i32, i32* %34
%54 = load i32, i32* %35
%55 = load i32, i32* %36
%56 = call i32 (i8**, i8*, ...) @asprintf(i8** %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %50, i32 %51, i32 %52, i32 %53, i32 %54, i32 %55)
%57 = load i8*, i8** %8
%58 = call i64 @strlen(i8* dereferenceable(1) %57)
%59 = add nsw i64 %58, 1
%60 = call i32 @cli_send(%struct.cli* %0, i8* %57, i64 %59)
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %48, %39
%64 = phi i32 [ -1, %39 ], [ 0, %48 ]
br label %65
65: ; preds = %63, %10
%66 = phi i32 [ -1, %10 ], [ %64, %63 ]
ret i32 %66
}