#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
void macchanger(char *inmon, int flag, char *monmac) {
  char tmp[25], buf[256];
  FILE *fp;
  int i;
  sprintf(tmp, "ifconfig %s down", inmon);
  system(tmp);
  if (flag == 0)
    sprintf(tmp, "macchanger -p %s", inmon);
  else {
    if (monmac == NULL)
      sprintf(tmp, "macchanger -A %s", inmon);
    else
      sprintf(tmp, "macchanger -A %s 1> /tmp/aircli-monmac", inmon);
  }
  system(tmp);
  if (monmac != NULL) {
    if ((fp = fopen("/tmp/aircli-monmac", "r")) == NULL) {
      fprintf(stderr, "Error opening file \"%s\": %s.\n", "/tmp/aircli-monmac",
              strerror(errno));
      monmac[0] = '\0';
      return;
    }
    for (i = 0; i < 3; i++) {
      if (fgets(buf, 256, fp) == NULL) {
        fprintf(stderr, "Error reading from file \"%s\": %s.\n",
                "/tmp/aircli-monmac", strerror(errno));
        monmac[0] = '\0';
        return;
      }
      fprintf(stdout, "%s", buf);
    }
    sscanf(buf, "%*s %*s %s", monmac);
  }
}


x86 assembly (clang, -O0):
<macchanger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <system@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11c6 <macchanger+0x56>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1080 <sprintf@plt>
jmp    1203 <macchanger+0x93>
cmpq   $0x0,-0x18(%rbp)
jne    11ea <macchanger+0x7a>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe42(%rip),%rsi
call   1080 <sprintf@plt>
jmp    11fe <macchanger+0x8e>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1080 <sprintf@plt>
jmp    1203 <macchanger+0x93>
lea    -0x40(%rbp),%rdi
call   1030 <system@plt>
cmpq   $0x0,-0x18(%rbp)
je     134b <macchanger+0x1db>
lea    0xe29(%rip),%rdi
lea    0xe35(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
jne    1282 <macchanger+0x112>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x150(%rbp),%edi
mov    %rax,%rcx
lea    0xdf4(%rip),%rsi
lea    0xdd8(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    134b <macchanger+0x1db>
movl   $0x0,-0x14c(%rbp)
cmpl   $0x3,-0x14c(%rbp)
jge    1334 <macchanger+0x1c4>
lea    -0x140(%rbp),%rdi
mov    -0x148(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1302 <macchanger+0x192>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x154(%rbp),%edi
mov    %rax,%rcx
lea    0xd92(%rip),%rsi
lea    0xd58(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    134b <macchanger+0x1db>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rdx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14c(%rbp)
jmp    128c <macchanger+0x11c>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd57(%rip),%rsi
call   1060 <sscanf@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macchanger>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe74(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1030 <system@plt>
test   %ebp,%ebp
je     11ce <macchanger+0x5e>
test   %r14,%r14
je     12de <macchanger+0x16e>
lea    0xe7d(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <system@plt>
jmp    11f4 <macchanger+0x84>
lea    0xe3c(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <system@plt>
test   %r14,%r14
je     1332 <macchanger+0x1c2>
lea    0xe4c(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12fd <macchanger+0x18d>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12be <macchanger+0x14e>
mov    0x2d9b(%rip),%r15
mov    (%r15),%edi
lea    0xdf1(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12be <macchanger+0x14e>
mov    (%r15),%edi
lea    0xdc3(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12be <macchanger+0x14e>
mov    (%r15),%edi
lea    0xd95(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdec(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
jmp    1332 <macchanger+0x1c2>
mov    0x2d1b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd9e(%rip),%rsi
jmp    131b <macchanger+0x1ab>
lea    0xd3d(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <system@plt>
jmp    1332 <macchanger+0x1c2>
mov    0x2cdc(%rip),%rax
mov    (%rax),%ebx
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd41(%rip),%rsi
lea    0xd25(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
movb   $0x0,(%r14)
add    $0x128,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"ifconfig %s down\00"
@.str.1 = [17 x i8] c"macchanger -p %s\00"
@.str.2 = [17 x i8] c"macchanger -A %s\00"
@.str.3 = [39 x i8] c"macchanger -A %s 1> /tmp/aircli-monmac\00"
@.str.4 = [19 x i8] c"/tmp/aircli-monmac\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [30 x i8] c"Error opening file \22%s\22: %s.\0A\00"
@errno = global i32 0
@.str.7 = [35 x i8] c"Error reading from file \22%s\22: %s.\0A\00"
@stdout = global i32 0
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [11 x i8] c"%*s %*s %s\00"
define void @macchanger(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [25 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%15 = call i32 @system(i8* %14)
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %34
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %4
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %33
29: ; preds = %22
%30 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29, %25
br label %34
34: ; preds = %33, %18
%35 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%36 = call i32 @system(i8* %35)
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %76
39: ; preds = %34
%40 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %40, i32** %9
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
store i8 0, i8* %48
br label %76
49: ; preds = %39
store i32 0, i32* %10
br label %50
50: ; preds = %69, %49
%51 = load i32, i32* %10
%52 = icmp slt i32 %51, 3
br i1 %52, label %53, label %72
53: ; preds = %50
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = load i32*, i32** %9
%56 = call i32* @fgets(i8* %54, i32 256, i32* %55)
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %65
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 0
store i8 0, i8* %64
br label %76
65: ; preds = %53
%66 = load i32, i32* @stdout
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %65
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %50
72: ; preds = %50
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%74 = load i8*, i8** %6
%75 = call i32 @sscanf(i8* %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %42, %58, %72, %34
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"ifconfig %s down\00"
@.str.1 = [17 x i8] c"macchanger -p %s\00"
@.str.2 = [17 x i8] c"macchanger -A %s\00"
@.str.3 = [39 x i8] c"macchanger -A %s 1> /tmp/aircli-monmac\00"
@.str.4 = [19 x i8] c"/tmp/aircli-monmac\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [30 x i8] c"Error opening file \22%s\22: %s.\0A\00"
@errno = global i32 0
@.str.7 = [35 x i8] c"Error reading from file \22%s\22: %s.\0A\00"
@stdout = global i32 0
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [11 x i8] c"%*s %*s %s\00"
define void @macchanger(i8* %0, i32 %1, i8* %2) {
%4 = alloca [25 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @system(i8* %6)
%10 = icmp eq i32 %1, 0
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = icmp eq i8* %2, null
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = call i32 @system(i8* %6)
br label %53
16: ; preds = %11
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%18 = call i32 @system(i8* %6)
br label %23
19: ; preds = %3
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = call i32 @system(i8* %6)
%22 = icmp eq i8* %2, null
br i1 %22, label %53, label %23
23: ; preds = %16, %19
%24 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32* @fgets(i8* %7, i32 256, i32* %24)
%28 = icmp eq i32* %27, null
br i1 %28, label %34, label %39
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %32)
store i8 0, i8* %2
br label %53
34: ; preds = %44, %39, %26
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %37)
store i8 0, i8* %2
br label %53
39: ; preds = %26
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%42 = call i32* @fgets(i8* %7, i32 256, i32* %24)
%43 = icmp eq i32* %42, null
br i1 %43, label %34, label %44
44: ; preds = %39
%45 = load i32, i32* @stdout
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%47 = call i32* @fgets(i8* %7, i32 256, i32* %24)
%48 = icmp eq i32* %47, null
br i1 %48, label %34, label %49
49: ; preds = %44
%50 = load i32, i32* @stdout
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%52 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %2)
br label %53
53: ; preds = %13, %19, %49, %34, %29
ret void
}