#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*/ valshort;
typedef int /*<<< orphan*/ valint;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
void *pcap_init(const char *fname) {
  int valint;
  short valshort;
  FILE *handle;
  handle = fopen(fname, "wb");
  if (!handle)
    return NULL;
  valint = (int)0xa1b2c3d4;
  fwrite((void *)&valint, sizeof(valint), 1, (FILE *)handle);
  ;
  valshort = (short)0x0002;
  fwrite((void *)&valshort, sizeof(valshort), 1, (FILE *)handle);
  ;
  valshort = (short)0x0004;
  fwrite((void *)&valshort, sizeof(valshort), 1, (FILE *)handle);
  ;
  valint = (int)0;
  fwrite((void *)&valint, sizeof(valint), 1, (FILE *)handle);
  ;
  valint = (int)0;
  fwrite((void *)&valint, sizeof(valint), 1, (FILE *)handle);
  ;
  valint = (int)4096;
  fwrite((void *)&valint, sizeof(valint), 1, (FILE *)handle);
  ;
  valint = (int)195;
  fwrite((void *)&valint, sizeof(valint), 1, (FILE *)handle);
  ;
  return (void *)handle;
}


x86 assembly (clang, -O0):
<pcap_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1158 <pcap_init+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1230 <pcap_init+0x110>
movl   $0xa1b2c3d4,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movw   $0x2,-0x16(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movw   $0x4,-0x16(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movl   $0x1000,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movl   $0xc3,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcap_init>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rsi
call   1030 <fopen@plt>
test   %rax,%rax
je     1216 <pcap_init+0xf6>
mov    %rax,%rbx
movl   $0xa1b2c3d4,0x8(%rsp)
a1
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fwrite@plt>
movw   $0x2,0xe(%rsp)
lea    0xe(%rsp),%r15
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movw   $0x4,0xe(%rsp)
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movl   $0x0,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movl   $0x0,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movl   $0x1000,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movl   $0xc3,0x8(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
jmp    1218 <pcap_init+0xf8>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i8* @pcap_init(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i16
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %36
12: ; preds = %1
store i32 -1582119980, i32* %4
%13 = bitcast i32* %4 to i8*
%14 = load i32*, i32** %6
%15 = call i32 @fwrite(i8* %13, i32 4, i32 1, i32* %14)
store i16 2, i16* %5
%16 = bitcast i16* %5 to i8*
%17 = load i32*, i32** %6
%18 = call i32 @fwrite(i8* %16, i32 2, i32 1, i32* %17)
store i16 4, i16* %5
%19 = bitcast i16* %5 to i8*
%20 = load i32*, i32** %6
%21 = call i32 @fwrite(i8* %19, i32 2, i32 1, i32* %20)
store i32 0, i32* %4
%22 = bitcast i32* %4 to i8*
%23 = load i32*, i32** %6
%24 = call i32 @fwrite(i8* %22, i32 4, i32 1, i32* %23)
store i32 0, i32* %4
%25 = bitcast i32* %4 to i8*
%26 = load i32*, i32** %6
%27 = call i32 @fwrite(i8* %25, i32 4, i32 1, i32* %26)
store i32 4096, i32* %4
%28 = bitcast i32* %4 to i8*
%29 = load i32*, i32** %6
%30 = call i32 @fwrite(i8* %28, i32 4, i32 1, i32* %29)
store i32 195, i32* %4
%31 = bitcast i32* %4 to i8*
%32 = load i32*, i32** %6
%33 = call i32 @fwrite(i8* %31, i32 4, i32 1, i32* %32)
%34 = load i32*, i32** %6
%35 = bitcast i32* %34 to i8*
store i8* %35, i8** %2
br label %36
36: ; preds = %12, %11
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define noalias i8* @pcap_init(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i16
%4 = bitcast i32* %2 to i8*
%5 = bitcast i16* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %1
store i32 -1582119980, i32* %2
%9 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %6)
store i16 2, i16* %3
%10 = call i32 @fwrite(i8* %5, i32 2, i32 1, i32* %6)
store i16 4, i16* %3
%11 = call i32 @fwrite(i8* %5, i32 2, i32 1, i32* %6)
store i32 0, i32* %2
%12 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %6)
store i32 0, i32* %2
%13 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %6)
store i32 4096, i32* %2
%14 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %6)
store i32 195, i32* %2
%15 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %6)
%16 = bitcast i32* %6 to i8*
br label %17
17: ; preds = %1, %8
%18 = phi i8* [ %16, %8 ], [ null, %1 ]
ret i8* %18
}