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

/* Variables and functions */
char *GetStringFromWeb();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ processString(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char mac[32] = "\0";
  char *web_str = NULL;
  char set_str[64] = "\0";
  FILE *fp;
  char *cmd = "cfg get mac";
  char buf[1000] = "\0";
  printf("Content-type:text/html\r\n\r\n");
  if ((web_str = GetStringFromWeb()) == NULL) {
    fprintf(stdout, "can't get string from web\n");
    exit(1);
  }
  processString(web_str, "macaddr", mac);
  memset(set_str, 0, sizeof(set_str));
  sprintf(set_str, "cfg set mac=%s", mac);
  system(set_str);
  if ((fp = popen(cmd, "r")) == NULL)
    perror("popen");
  while ((fgets(buf, 1000, fp)) != NULL)
    printf("%s\n", buf);
  pclose(fp);
  if (strstr(buf, mac) != NULL) {
    printf("successful :)\n");
  } else {
    printf("failed :(\n");
  }
  free(web_str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
movq   $0x0,-0x38(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    0xdd8(%rip),%rax
mov    %rax,-0x90(%rbp)
lea    -0x480(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1070 <memset@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10d0 <GetStringFromWeb@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1284 <main+0xa4>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xdaf(%rip),%rsi
call   10a0 <processString@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xd93(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <system@plt>
mov    -0x90(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    12f5 <main+0x115>
lea    0xd69(%rip),%rdi
call   10c0 <perror@plt>
jmp    12fa <main+0x11a>
lea    -0x480(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    $0x3e8,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1336 <main+0x156>
lea    -0x480(%rbp),%rsi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12fa <main+0x11a>
mov    -0x88(%rbp),%rdi
call   1060 <pclose@plt>
lea    -0x480(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1100 <strstr@plt>
cmp    $0x0,%rax
je     136f <main+0x18f>
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    137d <main+0x19d>
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x450,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x60(%rsp),%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe20(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10d0 <GetStringFromWeb@plt>
test   %rax,%rax
je     1334 <main+0x154>
mov    %rax,%r14
lea    0xde4(%rip),%rsi
mov    %rsp,%r15
mov    %rax,%rdi
mov    %r15,%rdx
call   10a0 <processString@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    0xdc3(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xd7a(%rip),%rdi
lea    0xda0(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1323 <main+0x143>
lea    0x60(%rsp),%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12dd <main+0xfd>
lea    0x60(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    12c0 <main+0xe0>
mov    %r15,%rdi
call   1060 <pclose@plt>
lea    0x60(%rsp),%rdi
mov    %rsp,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
lea    0xd62(%rip),%rax
lea    0xd65(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd14(%rip),%rdi
call   10c0 <perror@plt>
jmp    129e <main+0xbe>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"cfg get mac\00"
@.str.1 = [27 x i8] c"Content-type:text/html\0D\0A\0D\0A\00"
@stdout = global i32 0
@.str.2 = [27 x i8] c"can't get string from web\0A\00"
@.str.3 = [8 x i8] c"macaddr\00"
@.str.4 = [15 x i8] c"cfg set mac=%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"popen\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [15 x i8] c"successful :)\0A\00"
@.str.9 = [11 x i8] c"failed :(\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca i8*
%8 = alloca [64 x i8]
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [32 x i8]* %6 to i8*
store i8* null, i8** %7
%13 = bitcast [64 x i8]* %8 to i8*
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %10
%14 = bitcast [1000 x i8]* %11 to i8*
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%16 = call i8* (...) @GetStringFromWeb()
store i8* %16, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%25 = call i32 @processString(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 64)
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%32 = call i32 @system(i8* %31)
%33 = load i8*, i8** %10
%34 = call i32* @popen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %34, i32** %9
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %22
%37 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %22
br label %39
39: ; preds = %44, %38
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%41 = load i32*, i32** %9
%42 = call i32* @fgets(i8* %40, i32 1000, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %45)
br label %39
47: ; preds = %39
%48 = load i32*, i32** %9
%49 = call i32 @pclose(i32* %48)
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%52 = call i32* @strstr(i8* %50, i8* %51)
%53 = icmp ne i32* %52, null
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %58
56: ; preds = %47
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"cfg get mac\00"
@stdout = global i32 0
@.str.2 = [27 x i8] c"can't get string from web\0A\00"
@.str.3 = [8 x i8] c"macaddr\00"
@.str.4 = [15 x i8] c"cfg set mac=%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"popen\00"
@str = [26 x i8] c"Content-type:text/html\0D\0A\0D\00"
@str.10 = [10 x i8] c"failed :(\00"
@str.11 = [14 x i8] c"successful :)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = alloca [1000 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%10 = tail call i8* (...) @GetStringFromWeb()
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stdout
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 @processString(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%18 = call i32 @memset(i8* %7, i32 0, i32 64)
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%20 = call i32 @system(i8* %7)
%21 = call i32* @popen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
%26 = call i32* @fgets(i8* %8, i32 1000, i32* %21)
%27 = icmp eq i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %25, %28
%29 = call i32 @puts(i8* %8)
%30 = call i32* @fgets(i8* %8, i32 1000, i32* %21)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %28
32: ; preds = %28, %25
%33 = call i32 @pclose(i32* %21)
%34 = call i32* @strstr(i8* %8, i8* %6)
%35 = icmp eq i32* %34, null
%36 = select i1 %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0)
%37 = call i32 @puts(i8* dereferenceable(1) %36)
%38 = call i32 @free(i8* %10)
ret i32 0
}