#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 */
struct gengetopt_args_info {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int cmdline_parser_dump(int /*<<< orphan*/ *, struct gengetopt_args_info *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *);
int /*<<< orphan*/ stderr;
int cmdline_parser_file_save(const char *filename,
                             struct gengetopt_args_info *args_info) {
  FILE *outfile;
  int i = 0;
  outfile = fopen(filename, "w");
  if (!outfile) {
    fprintf(stderr, "%s: cannot open file for writing: %s\n", "sgsnemu",
            filename);
    return EXIT_FAILURE;
  }
  i = cmdline_parser_dump(outfile, args_info);
  fclose(outfile);
  return i;
}


x86 assembly (clang, -O0):
<cmdline_parser_file_save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <cmdline_parser_file_save+0x67>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe78(%rip),%rsi
lea    0xe97(%rip),%rdx
call   1050 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <cmdline_parser_file_save+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <cmdline_parser_dump@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdline_parser_file_save>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117a <cmdline_parser_file_save+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <cmdline_parser_dump@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
jmp    11a2 <cmdline_parser_file_save+0x62>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
lea    0xe97(%rip),%rdx
mov    %r15,%rcx
call   1050 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gengetopt_args_info = type { i32 }
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"%s: cannot open file for writing: %s\0A\00"
@.str.2 = [8 x i8] c"sgsnemu\00"
@EXIT_FAILURE = global i32 0
define i32 @cmdline_parser_file_save(i8* %0, %struct.gengetopt_args_info* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.gengetopt_args_info*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store %struct.gengetopt_args_info* %1, %struct.gengetopt_args_info** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %24
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = load %struct.gengetopt_args_info*, %struct.gengetopt_args_info** %5
%20 = call i32 @cmdline_parser_dump(i32* %18, %struct.gengetopt_args_info* %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %17, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.gengetopt_args_info = type { i32 }
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"%s: cannot open file for writing: %s\0A\00"
@.str.2 = [8 x i8] c"sgsnemu\00"
@EXIT_FAILURE = global i32 0
define i32 @cmdline_parser_file_save(i8* %0, %struct.gengetopt_args_info* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @EXIT_FAILURE
br label %12
9: ; preds = %2
%10 = tail call i32 @cmdline_parser_dump(i32* %3, %struct.gengetopt_args_info* %1)
%11 = tail call i32 @fclose(i32* %3)
br label %12
12: ; preds = %9, %5
%13 = phi i32 [ %10, %9 ], [ %8, %5 ]
ret i32 %13
}