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

/* Variables and functions */
int /*<<< orphan*/ fatal_error(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf_keypoints(int /*<<< orphan*/ *,
                                     struct sift_keypoints const *, int);
void sift_save_keypoints(const struct sift_keypoints *keys, const char *name,
                         int flag) {
  FILE *f = fopen(name, "w");
  if (!f) {
    fatal_error("Failed to open %s for writing\n", name);
  }
  fprintf_keypoints(f, keys, flag);
  fclose(f);
}


x86 assembly (clang, -O0):
<sift_save_keypoints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1182 <sift_save_keypoints+0x42>
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <fatal_error@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <fprintf_keypoints@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sift_save_keypoints>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1176 <sift_save_keypoints+0x36>
lea    0xe94(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fatal_error@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <fprintf_keypoints@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
%struct.sift_keypoints = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [31 x i8] c"Failed to open %s for writing\0A\00"
define void @sift_save_keypoints(%struct.sift_keypoints* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sift_keypoints*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store %struct.sift_keypoints* %0, %struct.sift_keypoints** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %3
%16 = load i32*, i32** %7
%17 = load %struct.sift_keypoints*, %struct.sift_keypoints** %4
%18 = load i32, i32* %6
%19 = call i32 @fprintf_keypoints(i32* %16, %struct.sift_keypoints* %17, i32 %18)
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
ret void
}

LLVM IR (-O2):
%struct.sift_keypoints = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [31 x i8] c"Failed to open %s for writing\0A\00"
define void @sift_save_keypoints(%struct.sift_keypoints* %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @fatal_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @fprintf_keypoints(i32* %4, %struct.sift_keypoints* %0, i32 %2)
%10 = tail call i32 @fclose(i32* %4)
ret void
}