#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 */

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int pcapwritehdr(int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int hcxopenpcapdump(char *pcapdumpname) {
  int fd;
  umask(0);
  fd = open(pcapdumpname, O_WRONLY | O_CREAT, 0644);
  if (fd == -1) {
    return -1;
  }
  if (pcapwritehdr(fd) == false) {
    close(fd);
    return 0;
  }
  return fd;
}


x86 assembly (clang, -O0):
<hcxopenpcapdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %edi,%edi
call   1040 <umask@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    0x2e91(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118c <hcxopenpcapdump+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <hcxopenpcapdump+0x77>
mov    -0x14(%rbp),%edi
call   1050 <pcapwritehdr@plt>
cmp    $0x0,%eax
jne    11b1 <hcxopenpcapdump+0x71>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <hcxopenpcapdump+0x77>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hcxopenpcapdump>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <umask@plt>
mov    0x2e7e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1187 <hcxopenpcapdump+0x47>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <pcapwritehdr@plt>
test   %eax,%eax
jne    118c <hcxopenpcapdump+0x4c>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %ebx,%ebx
jmp    118c <hcxopenpcapdump+0x4c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @hcxopenpcapdump(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @umask(i32 0)
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9, i32 420)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %23
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @pcapwritehdr(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
store i32 0, i32* %2
br label %23
21: ; preds = %14
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %23
23: ; preds = %21, %18, %13
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @hcxopenpcapdump(i8* nocapture %0) {
%2 = tail call i32 @umask(i32 0)
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5, i32 420)
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = tail call i32 @pcapwritehdr(i32 %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @close(i32 %6)
br label %13
13: ; preds = %8, %1, %11
%14 = phi i32 [ 0, %11 ], [ -1, %1 ], [ %6, %8 ]
ret i32 %14
}