#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_name_wanip_postfile(char *postfile, char *dname, char *qname,
                                      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=set\n");
  fprintf(fpt, "&dname=%s\n", dname);
  fprintf(fpt, "&qname=%s\n", qname);
  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_name_wanip_postfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0xd8(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xd8(%rbp)
cmp    $0x0,%rax
jne    11b3 <create_update_name_wanip_postfile+0x53>
movl   $0xffffff31,-0x4(%rbp)
jmp    12ce <create_update_name_wanip_postfile+0x16e>
mov    -0xd8(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x70(%rbp),%rdi
mov    $0x40,%esi
call   1030 <get_serial_number@plt>
mov    -0xd8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1040 <get_mac_address@plt>
mov    -0xd8(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
mov    $0x40,%ecx
call   1070 <gen_encrypt_key@plt>
mov    -0xd8(%rbp),%rdi
lea    -0xd0(%rbp),%rdx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
lea    0xd9e(%rip),%rsi
lea    0xda0(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_update_name_wanip_postfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbp
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1292 <create_update_name_wanip_postfile+0x122>
mov    %rax,%rbx
lea    0xe5a(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xe4e(%rip),%rsi
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x60(%rsp),%r12
mov    %r12,%rdi
mov    $0x40,%esi
call   1030 <get_serial_number@plt>
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <get_mac_address@plt>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x20(%rsp),%r13
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    $0x40,%ecx
call   1070 <gen_encrypt_key@plt>
lea    0xde8(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdd4(%rip),%rsi
lea    0xdd6(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1298 <create_update_name_wanip_postfile+0x128>
mov    $0xffffff31,%r15d
mov    %r15d,%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 = [13 x i8] c"subfunc=set\0A\00"
@.str.2 = [11 x i8] c"&dname=%s\0A\00"
@.str.3 = [11 x i8] c"&qname=%s\0A\00"
@.str.4 = [8 x i8] c"&sn=%s\0A\00"
@.str.5 = [9 x i8] c"&mac=%s\0A\00"
@.str.6 = [9 x i8] c"&key=%s\0A\00"
@.str.7 = [11 x i8] c"&wanIP=%s\0A\00"
@.str.8 = [9 x i8] c"&ver=%s\0A\00"
@.str.9 = [4 x i8] c"1.1\00"
define i32 @create_update_name_wanip_postfile(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [64 x i8]
%11 = alloca [32 x i8]
%12 = alloca [64 x i8]
%13 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32* null, i32** %13
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -207, i32* %5
br label %51
18: ; preds = %4
%19 = load i32*, i32** %13
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32*, i32** %13
%22 = load i8*, i8** %7
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %13
%25 = load i8*, i8** %8
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%28 = call i32 @get_serial_number(i8* %27, i32 64)
%29 = load i32*, i32** %13
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%33 = call i32 @get_mac_address(i8* %32, i32 32)
%34 = load i32*, i32** %13
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%40 = call i32 @gen_encrypt_key(i8* %37, i8* %38, i8* %39, i32 64)
%41 = load i32*, i32** %13
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = load i32*, i32** %13
%45 = load i8*, i8** %9
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %13
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%49 = load i32*, i32** %13
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %5
br label %51
51: ; preds = %18, %17
%52 = load i32, i32* %5
ret i32 %52
}

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