#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ sf_write_header(int /*<<< orphan*/ *, int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
FILE *sr_dump_open(const char *fname, int thiszone, int snaplen) {
  FILE *fp;
  if (fname[0] == '-' && fname[1] == '\0')
    fp = stdout;
  else {
    fp = fopen(fname, "w");
    if (fp == NULL) {
      fprintf(stderr, "sr_dump_open: can't open %s", fname);
      return (NULL);
    }
  }
  sf_write_header(fp, 1, thiszone, snaplen);
  return fp;
}


x86 assembly (clang, -O0):
<sr_dump_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1176 <sr_dump_open+0x46>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1176 <sr_dump_open+0x46>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11c0 <sr_dump_open+0x90>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <sr_dump_open+0x8b>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe59(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11dc <sr_dump_open+0xac>
jmp    11c0 <sr_dump_open+0x90>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x1,%esi
call   1040 <sf_write_header@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sr_dump_open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    114b <sr_dump_open+0x1b>
cmpb   $0x0,0x1(%rbx)
je     117e <sr_dump_open+0x4e>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1188 <sr_dump_open+0x58>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xor    %ebp,%ebp
jmp    119b <sr_dump_open+0x6b>
mov    0x2e53(%rip),%rax
mov    (%rax),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <sf_write_header@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"sr_dump_open: can't open %s\00"
define i32* @sr_dump_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 45
br i1 %13, label %14, label %22
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i32*, i32** @stdout
store i32* %21, i32** %8
br label %32
22: ; preds = %14, %3
%23 = load i8*, i8** %5
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %8
%25 = load i32*, i32** %8
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32* null, i32** %4
br label %38
31: ; preds = %22
br label %32
32: ; preds = %31, %20
%33 = load i32*, i32** %8
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = call i32 @sf_write_header(i32* %33, i32 1, i32 %34, i32 %35)
%37 = load i32*, i32** %8
store i32* %37, i32** %4
br label %38
38: ; preds = %32, %27
%39 = load i32*, i32** %4
ret i32* %39
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"sr_dump_open: can't open %s\00"
define i32* @sr_dump_open(i8* %0, i32 %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 45
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = load i32*, i32** @stdout
br label %18
12: ; preds = %6, %3
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
18: ; preds = %12, %10
%19 = phi i32* [ %11, %10 ], [ %13, %12 ]
%20 = tail call i32 @sf_write_header(i32* %19, i32 1, i32 %1, i32 %2)
br label %21
21: ; preds = %18, %15
%22 = phi i32* [ %19, %18 ], [ null, %15 ]
ret i32* %22
}