#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 */
scalar_t__ copy_contents(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int create_backup(const char *backup_file, FILE *fptr) {
  FILE *fbackup;
  fbackup = fopen(backup_file, "wt");
  if (!fbackup) {
    fprintf(stderr,
            "Error creating backup password file \"%s\", not continuing.\n",
            backup_file);
    return 1;
  }
  if (copy_contents(fptr, fbackup)) {
    fprintf(
        stderr,
        "Error copying data to backup password file \"%s\", not continuing.\n",
        backup_file);
    fclose(fbackup);
    return 1;
  }
  fclose(fbackup);
  rewind(fptr);
  return 0;
}


x86 assembly (clang, -O0):
<create_backup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <create_backup+0x54>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <create_backup+0xb2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <copy_contents@plt>
cmp    $0x0,%rax
je     11e9 <create_backup+0x99>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1202 <create_backup+0xb2>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_backup>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a6 <create_backup+0x56>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <copy_contents@plt>
test   %rax,%rax
je     11c5 <create_backup+0x75>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11d7 <create_backup+0x87>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11d7 <create_backup+0x87>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1040 <rewind@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wt\00"
@stderr = global i32 0
@.str.1 = [59 x i8] c"Error creating backup password file \22%s\22, not continuing.\0A\00"
@.str.2 = [66 x i8] c"Error copying data to backup password file \22%s\22, not continuing.\0A\00"
define i32 @create_backup(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %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 ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %31
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = load i32*, i32** %6
%18 = call i64 @copy_contents(i32* %16, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
store i32 1, i32* %3
br label %31
26: ; preds = %15
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @rewind(i32* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %26, %20, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"wt\00"
@stderr = global i32 0
@.str.1 = [59 x i8] c"Error creating backup password file \22%s\22, not continuing.\0A\00"
@.str.2 = [66 x i8] c"Error copying data to backup password file \22%s\22, not continuing.\0A\00"
define i32 @create_backup(i8* %0, i32* %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 ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
8: ; preds = %2
%9 = tail call i64 @copy_contents(i32* %1, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = tail call i32 @fclose(i32* %3)
br label %18
15: ; preds = %8
%16 = tail call i32 @fclose(i32* %3)
%17 = tail call i32 @rewind(i32* %1)
br label %18
18: ; preds = %15, %11, %5
%19 = phi i32 [ 1, %11 ], [ 0, %15 ], [ 1, %5 ]
ret i32 %19
}