#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*/ P0(char *);
int /*<<< orphan*/ P1(char *, unsigned long);
int /*<<< orphan*/ TCPIP_SNPRINTF0(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(unsigned char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void HDR_WriteBinaryFile(unsigned char *pHDRMsg, unsigned long ulMsgLen,
                         unsigned long ulMsgType, unsigned long ulScanId) {
  char szFileName[128];
  FILE *fpWrite = NULL;
  if (1 == ulMsgType) {
    (void)TCPIP_SNPRINTF0(szFileName, 128,
                          P1("e:/tcpiphealth%d.file", ulScanId));
  } else {
    (void)TCPIP_SNPRINTF0(szFileName, 128, P0("e:/tcpiplastword.file"));
  }
  fpWrite = fopen(szFileName, "ab");
  if (NULL == fpWrite) {
    printf("\r\nError occurs while openning file.");
    return;
  }
  if (fwrite(pHDRMsg, ulMsgLen, 1, fpWrite) != 1) {
    printf("\r\nError occurs while writing file.");
  }
  fclose(fpWrite);
  return;
}


x86 assembly (clang, -O0):
<HDR_WriteBinaryFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    $0x1,%eax
cmp    -0x18(%rbp),%rax
jne    11db <HDR_WriteBinaryFile+0x6b>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1070 <P1@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%edx
mov    $0x80,%esi
call   1060 <TCPIP_SNPRINTF0@plt>
jmp    1208 <HDR_WriteBinaryFile+0x98>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    0xe26(%rip),%rdi
call   1030 <P0@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
mov    $0x80,%esi
call   1060 <TCPIP_SNPRINTF0@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xa8(%rbp)
xor    %eax,%eax
cmp    -0xa8(%rbp),%rax
jne    1242 <HDR_WriteBinaryFile+0xd2>
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
jmp    127c <HDR_WriteBinaryFile+0x10c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0xa8(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     1270 <HDR_WriteBinaryFile+0x100>
lea    0xde8(%rip),%rdi
call   1050 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HDR_WriteBinaryFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x1,%rdx
jne    1199 <HDR_WriteBinaryFile+0x29>
lea    0xe71(%rip),%rdi
mov    %rcx,%rsi
call   1070 <P1@plt>
jmp    11a5 <HDR_WriteBinaryFile+0x35>
lea    0xe76(%rip),%rdi
call   1030 <P0@plt>
mov    %eax,%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <TCPIP_SNPRINTF0@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fc <HDR_WriteBinaryFile+0x8c>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     11f2 <HDR_WriteBinaryFile+0x82>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1208 <HDR_WriteBinaryFile+0x98>
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"e:/tcpiphealth%d.file\00"
@.str.1 = [22 x i8] c"e:/tcpiplastword.file\00"
@.str.2 = [3 x i8] c"ab\00"
@.str.3 = [36 x i8] c"\0D\0AError occurs while openning file.\00"
@.str.4 = [35 x i8] c"\0D\0AError occurs while writing file.\00"
define void @HDR_WriteBinaryFile(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca [128 x i8]
%10 = alloca i32*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i32* null, i32** %10
%11 = load i64, i64* %7
%12 = icmp eq i64 1, %11
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%15 = load i64, i64* %8
%16 = call i32 @P1(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i32 @TCPIP_SNPRINTF0(i8* %14, i32 128, i32 %16)
br label %22
18: ; preds = %4
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%20 = call i32 @P0(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @TCPIP_SNPRINTF0(i8* %19, i32 128, i32 %20)
br label %22
22: ; preds = %18, %13
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %10
%25 = load i32*, i32** %10
%26 = icmp eq i32* null, %25
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %40
29: ; preds = %22
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = load i32*, i32** %10
%33 = call i32 @fwrite(i8* %30, i64 %31, i32 1, i32* %32)
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i32*, i32** %10
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %27
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"e:/tcpiphealth%d.file\00"
@.str.1 = [22 x i8] c"e:/tcpiplastword.file\00"
@.str.2 = [3 x i8] c"ab\00"
@.str.3 = [36 x i8] c"\0D\0AError occurs while openning file.\00"
@.str.4 = [35 x i8] c"\0D\0AError occurs while writing file.\00"
define void @HDR_WriteBinaryFile(i8* nocapture %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = icmp eq i64 %2, 1
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @P1(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %3)
br label %12
10: ; preds = %4
%11 = tail call i32 @P0(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %11, %10 ], [ %9, %8 ]
%14 = call i32 @TCPIP_SNPRINTF0(i8* %6, i32 128, i32 %13)
%15 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %26
19: ; preds = %12
%20 = call i32 @fwrite(i8* %0, i64 %1, i32 1, i32* %15)
%21 = icmp eq i32 %20, 1
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = call i32 @fclose(i32* %15)
br label %26
26: ; preds = %24, %17
ret void
}