#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*/ EXIT_FAILURE;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int write(int, char *, int);
void backup_file(int fp_bkp, char *buffer, int buf_size) {
  int wr_bytes = 0;
  do {
    wr_bytes = write(fp_bkp, buffer, buf_size);
    if (wr_bytes < 0) {
      error("writing to backup file!");
      exit(EXIT_FAILURE);
    }
  } while (wr_bytes < buf_size);
}


x86 assembly (clang, -O0):
<backup_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117f <backup_file+0x4f>
lea    0xe94(%rip),%rdi
call   1040 <error@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1184 <backup_file+0x54>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1149 <backup_file+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_file>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1159 <backup_file+0x29>
cmp    %ebx,%eax
jl     1140 <backup_file+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea0(%rip),%rdi
call   1040 <error@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"writing to backup file!\00"
@EXIT_FAILURE = global i32 0
define void @backup_file(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %20, %3
%9 = load i32, i32* %4
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @write(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %19
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %8, label %24
24: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"writing to backup file!\00"
@EXIT_FAILURE = global i32 0
define void @backup_file(i32 %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %11, %3
%5 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %4
%12 = icmp slt i32 %5, %2
br i1 %12, label %4, label %13
13: ; preds = %11
ret void
}