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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gen_encrypt_key(char *, char *, char *, int);
int /*<<< orphan*/ get_mac_address(char *, int);
int /*<<< orphan*/ get_serial_number(char *, int);
int create_update_wanip_postfile(char *postfile, char *wan_ip) {
  char serial_number[64], mac[32], key[64];
  FILE *fpt = NULL;
  if ((fpt = fopen(postfile, "w+")) == NULL) {
    return (-100 - 107);
  }
  fprintf(fpt, "subfunc=update\n");
  get_serial_number(serial_number, sizeof(serial_number));
  fprintf(fpt, "&sn=%s\n", serial_number);
  get_mac_address(mac, sizeof(mac));
  fprintf(fpt, "&mac=%s\n", mac);
  gen_encrypt_key(serial_number, mac, key, sizeof(key));
  fprintf(fpt, "&key=%s\n", key);
  fprintf(fpt, "&wanIP=%s\n", wan_ip);
  fprintf(fpt, "&ver=%s\n", "1.1");
  fclose(fpt);
  return 0;
}


x86 assembly (clang, -O0):
<create_update_wanip_postfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0xc8(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
jne    11ab <create_update_wanip_postfile+0x4b>
movl   $0xffffff31,-0x4(%rbp)
jmp    128b <create_update_wanip_postfile+0x12b>
mov    -0xc8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   1030 <get_serial_number@plt>
mov    -0xc8(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x20,%esi
call   1040 <get_mac_address@plt>
mov    -0xc8(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
mov    $0x40,%ecx
call   1070 <gen_encrypt_key@plt>
mov    -0xc8(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc8(%rbp),%rdi
lea    0xdce(%rip),%rsi
lea    0xdd0(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc8(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_update_wanip_postfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%r14
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1264 <create_update_wanip_postfile+0xf4>
mov    %rax,%rbx
lea    0xe60(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0x60(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
call   1030 <get_serial_number@plt>
lea    0xe45(%rip),%rsi
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <get_mac_address@plt>
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x20(%rsp),%r13
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    $0x40,%ecx
call   1070 <gen_encrypt_key@plt>
lea    0xe03(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdef(%rip),%rsi
lea    0xdf1(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    126a <create_update_wanip_postfile+0xfa>
mov    $0xffffff31,%r12d
mov    %r12d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [16 x i8] c"subfunc=update\0A\00"
@.str.2 = [8 x i8] c"&sn=%s\0A\00"
@.str.3 = [9 x i8] c"&mac=%s\0A\00"
@.str.4 = [9 x i8] c"&key=%s\0A\00"
@.str.5 = [11 x i8] c"&wanIP=%s\0A\00"
@.str.6 = [9 x i8] c"&ver=%s\0A\00"
@.str.7 = [4 x i8] c"1.1\00"
define i32 @create_update_wanip_postfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [64 x i8]
%7 = alloca [32 x i8]
%8 = alloca [64 x i8]
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -207, i32* %3
br label %41
14: ; preds = %2
%15 = load i32*, i32** %9
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%18 = call i32 @get_serial_number(i8* %17, i32 64)
%19 = load i32*, i32** %9
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%23 = call i32 @get_mac_address(i8* %22, i32 32)
%24 = load i32*, i32** %9
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%30 = call i32 @gen_encrypt_key(i8* %27, i8* %28, i8* %29, i32 64)
%31 = load i32*, i32** %9
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = load i32*, i32** %9
%35 = load i8*, i8** %5
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %9
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %14, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [16 x i8] c"subfunc=update\0A\00"
@.str.2 = [8 x i8] c"&sn=%s\0A\00"
@.str.3 = [9 x i8] c"&mac=%s\0A\00"
@.str.4 = [9 x i8] c"&key=%s\0A\00"
@.str.5 = [11 x i8] c"&wanIP=%s\0A\00"
@.str.6 = [9 x i8] c"&ver=%s\0A\00"
@.str.7 = [4 x i8] c"1.1\00"
define i32 @create_update_wanip_postfile(i8* nocapture %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 15, i64 1, i32* %9)
%13 = call i32 @get_serial_number(i8* %6, i32 64)
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%15 = call i32 @get_mac_address(i8* %7, i32 32)
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%17 = call i32 @gen_encrypt_key(i8* %6, i8* %7, i8* %8, i32 64)
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 @fclose(i32* %9)
br label %22
22: ; preds = %2, %11
%23 = phi i32 [ 0, %11 ], [ -207, %2 ]
ret i32 %23
}