#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 */

/* Variables and functions */
int /*<<< orphan*/ File_Close(int);
int File_Open(char const *);
int /*<<< orphan*/ SEEK_END;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, void *, int);
int File_AppendRecord(const char *FileName, void *Record, int Record_Len) {
  int fd;
  if ((fd = File_Open(FileName)) < 0)
    return -1;
  if (lseek(fd, 0, SEEK_END) < 0) {
    File_Close(fd);
    return -1;
  }
  if (write(fd, Record, Record_Len) != Record_Len) {
    File_Close(fd);
    return -1;
  }
  File_Close(fd);
  return Record_Len;
}


x86 assembly (clang, -O0):
<File_AppendRecord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <File_Open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1174 <File_AppendRecord+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <File_AppendRecord+0x9f>
mov    -0x20(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    11a5 <File_AppendRecord+0x65>
mov    -0x20(%rbp),%edi
call   1060 <File_Close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <File_AppendRecord+0x9f>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     11d1 <File_AppendRecord+0x91>
mov    -0x20(%rbp),%edi
call   1060 <File_Close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <File_AppendRecord+0x9f>
mov    -0x20(%rbp),%edi
call   1060 <File_Close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<File_AppendRecord>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
call   1050 <File_Open@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     119f <File_AppendRecord+0x5f>
mov    %eax,%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1198 <File_AppendRecord+0x58>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <File_Close@plt>
cmp    %r14d,%ebp
mov    $0xffffffff,%ebp
cmove  %r14d,%ebp
jmp    119f <File_AppendRecord+0x5f>
mov    %ebx,%edi
call   1060 <File_Close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
define i32 @File_AppendRecord(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @File_Open(i8* %9)
store i32 %10, i32* %8
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %35
13: ; preds = %3
%14 = load i32, i32* %8
%15 = load i32, i32* @SEEK_END
%16 = call i64 @lseek(i32 %14, i32 0, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %8
%20 = call i32 @File_Close(i32 %19)
store i32 -1, i32* %4
br label %35
21: ; preds = %13
%22 = load i32, i32* %8
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %8
%30 = call i32 @File_Close(i32 %29)
store i32 -1, i32* %4
br label %35
31: ; preds = %21
%32 = load i32, i32* %8
%33 = call i32 @File_Close(i32 %32)
%34 = load i32, i32* %7
store i32 %34, i32* %4
br label %35
35: ; preds = %31, %28, %18, %12
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@SEEK_END = global i32 0
define i32 @File_AppendRecord(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @File_Open(i8* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @lseek(i32 %4, i32 0, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @File_Close(i32 %4)
br label %17
12: ; preds = %6
%13 = tail call i32 @write(i32 %4, i8* %1, i32 %2)
%14 = icmp eq i32 %13, %2
%15 = tail call i32 @File_Close(i32 %4)
%16 = select i1 %14, i32 %2, i32 -1
br label %17
17: ; preds = %12, %3, %10
%18 = phi i32 [ -1, %10 ], [ -1, %3 ], [ %16, %12 ]
ret i32 %18
}