#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 */
char *base64encode(char *, size_t *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
size_t strlen(char *);
char *strtok(unsigned char *, char *);
int main() {
  char *base64enc = NULL;
  FILE *xFile, *oFile;
  unsigned char buf[1024];
  char *delim = "$";
  char *tmp = NULL;
  xFile = fopen("/tmp/wifi_site_not_encode", "r");
  oFile = fopen("/tmp/wifi_site", "w");
  if (xFile == NULL) {
    printf("open wifi_site_not_encode fail\n");
  } else {
    while (fgets(buf, 1024, xFile) != NULL) {
      tmp = strtok(buf, delim);
      int counter = 0;
      while (tmp != NULL) {
        size_t len = strlen(tmp);
        if (counter == 1) {
          base64enc = base64encode(tmp, &len);
          fprintf(oFile, "%s$", base64enc);
        } else
          fprintf(oFile, "%s", tmp);
        tmp = strtok(NULL, delim);
        if (tmp != NULL)
          fprintf(oFile, "$", tmp);
        counter++;
      }
    }
    fclose(xFile);
  }
  fclose(oFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x428(%rbp)
movq   $0x0,-0x430(%rbp)
lea    0xe46(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fd <main+0x7d>
lea    0xe3a(%rip),%rdi
call   1060 <printf@plt>
jmp    1318 <main+0x198>
jmp    1202 <main+0x82>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     130f <main+0x18f>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x430(%rbp)
movl   $0x0,-0x434(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     130a <main+0x18a>
mov    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x440(%rbp)
cmpl   $0x1,-0x434(%rbp)
jne    12a3 <main+0x123>
mov    -0x430(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1040 <base64encode@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdb4(%rip),%rsi
call   1080 <fprintf@plt>
jmp    12ba <main+0x13a>
mov    -0x20(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd9c(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x428(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <strtok@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     12f6 <main+0x176>
mov    -0x20(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd5e(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1245 <main+0xc5>
jmp    1202 <main+0x82>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe58(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe5e(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %r14,%r14
je     1318 <main+0x188>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     130e <main+0x17e>
lea    0xe37(%rip),%r15
lea    0x10(%rsp),%r12
jmp    1219 <main+0x89>
nop
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     130e <main+0x17e>
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <base64encode@plt>
mov    %rbx,%rdi
lea    0xda5(%rip),%rsi
mov    %rax,%rdx
call   1090 <fprintf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rsi
call   1070 <fputs@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10b0 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     1200 <main+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
jmp    12d0 <main+0x140>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1324 <main+0x194>
lea    0xd12(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"$\00"
@.str.1 = [26 x i8] c"/tmp/wifi_site_not_encode\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [15 x i8] c"/tmp/wifi_site\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [32 x i8] c"open wifi_site_not_encode fail\0A\00"
@.str.6 = [4 x i8] c"%s$\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %1
store i8* null, i8** %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %3
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %60
16: ; preds = %0
br label %17
17: ; preds = %56, %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 1024, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %57
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = call i8* @strtok(i8* %23, i8* %24)
store i8* %25, i8** %7
store i32 0, i32* %8
br label %26
26: ; preds = %53, %22
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %56
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %30)
store i64 %31, i64* %9
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = call i8* @base64encode(i8* %35, i64* %9)
store i8* %36, i8** %2
%37 = load i32*, i32** %4
%38 = load i8*, i8** %2
%39 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %38)
br label %44
40: ; preds = %29
%41 = load i32*, i32** %4
%42 = load i8*, i8** %7
%43 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %40, %34
%45 = load i8*, i8** %6
%46 = call i8* @strtok(i8* null, i8* %45)
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32*, i32** %4
%51 = load i8*, i8** %7
%52 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %49, %44
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %26
56: ; preds = %26
br label %17
57: ; preds = %17
%58 = load i32*, i32** %3
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %57, %14
%61 = load i32*, i32** %4
%62 = call i32 @fclose(i32* %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"$\00"
@.str.1 = [26 x i8] c"/tmp/wifi_site_not_encode\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [15 x i8] c"/tmp/wifi_site\00"
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%s$\00"
@str = [31 x i8] c"open wifi_site_not_encode fail\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%6 = icmp eq i32* %4, null
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %48, label %10
10: ; preds = %7
%11 = bitcast i64* %2 to i8*
br label %17
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %50
14: ; preds = %40, %33, %25, %17
%15 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%16 = icmp eq i32* %15, null
br i1 %16, label %48, label %17
17: ; preds = %10, %14
%18 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %14, label %20
20: ; preds = %17
%21 = call i64 @strlen(i8* %18)
store i64 %21, i64* %2
%22 = call i32 @fputs(i8* %18, i32* %5)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %20
br label %14
26: ; preds = %20
%27 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %23)
%28 = call i64 @strlen(i8* %23)
store i64 %28, i64* %2
%29 = call i8* @base64encode(i8* %23, i64* %2)
%30 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %26
br label %14
34: ; preds = %26
%35 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %31)
%36 = call i64 @strlen(i8* %31)
store i64 %36, i64* %2
%37 = call i32 @fputs(i8* %31, i32* %5)
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %41, %34
br label %14
41: ; preds = %34, %41
%42 = phi i8* [ %46, %41 ], [ %38, %34 ]
%43 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = call i64 @strlen(i8* %42)
store i64 %44, i64* %2
%45 = call i32 @fputs(i8* %42, i32* %5)
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%47 = icmp eq i8* %46, null
br i1 %47, label %40, label %41
48: ; preds = %14, %7
%49 = call i32 @fclose(i32* %4)
br label %50
50: ; preds = %48, %12
%51 = call i32 @fclose(i32* %5)
ret i32 0
}