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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ writeTrajectory(int /*<<< orphan*/ *,
                                   struct Trajectory const *);
int saveTrajectory(const char *filename, const struct Trajectory *trajectory) {
  FILE *file;
  file = fopen(filename, "wb");
  if (!file) {
    fprintf(stderr, "saveTrajectory: Error opening %s for read\n", filename);
    return 1;
  }
  writeTrajectory(file, trajectory);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<saveTrajectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <saveTrajectory+0x54>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <saveTrajectory+0x71>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <writeTrajectory@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveTrajectory>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1176 <saveTrajectory+0x36>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <writeTrajectory@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1193 <saveTrajectory+0x53>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Trajectory = type { i32 }
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"saveTrajectory: Error opening %s for read\0A\00"
define i32 @saveTrajectory(i8* %0, %struct.Trajectory* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.Trajectory*
%6 = alloca i32*
store i8* %0, i8** %4
store %struct.Trajectory* %1, %struct.Trajectory** %5
%7 = load i8*, i8** %4
%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 %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %21
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load %struct.Trajectory*, %struct.Trajectory** %5
%18 = call i32 @writeTrajectory(i32* %16, %struct.Trajectory* %17)
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
store i32 0, i32* %3
br label %21
21: ; preds = %15, %11
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.Trajectory = type { i32 }
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"saveTrajectory: Error opening %s for read\0A\00"
define i32 @saveTrajectory(i8* %0, %struct.Trajectory* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
8: ; preds = %2
%9 = tail call i32 @writeTrajectory(i32* %3, %struct.Trajectory* %1)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %8 ], [ 1, %5 ]
ret i32 %12
}