#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void WriteContent(const char *nodename, int tfd) {
  int rfd;
  int cnt;
  char buf[2048];
  if ((rfd = open(nodename, O_RDONLY)) == -1) {
    perror("error opening backup file:  ");
    return;
  }
  printf("backup %s\n", nodename);
  while ((cnt = read(rfd, buf, 2048)) > 0) {
    write(tfd, buf, cnt);
  }
  close(rfd);
}


x86 assembly (clang, -O0):
<WriteContent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11a1 <WriteContent+0x41>
lea    0xe69(%rip),%rdi
call   1080 <perror@plt>
jmp    11f0 <WriteContent+0x90>
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11e8 <WriteContent+0x88>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    11b1 <WriteContent+0x51>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteContent>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11e2 <WriteContent+0x82>
mov    %eax,%ebp
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x800,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11d0 <WriteContent+0x70>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11b0 <WriteContent+0x50>
mov    %ebp,%edi
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>
lea    0xe17(%rip),%rdi
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [29 x i8] c"error opening backup file: \00"
@.str.1 = [11 x i8] c"backup %s\0A\00"
define void @WriteContent(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2048 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %30
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %22, %14
%18 = load i32, i32* %5
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 2048)
store i32 %20, i32* %6
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* %4
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %6
%26 = call i32 @write(i32 %23, i8* %24, i32 %25)
br label %17
27: ; preds = %17
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %12
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [29 x i8] c"error opening backup file: \00"
@.str.1 = [11 x i8] c"backup %s\0A\00"
define void @WriteContent(i8* %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %21
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = call i32 @read(i32 %6, i8* %4, i32 2048)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10, %14
%15 = phi i32 [ %17, %14 ], [ %12, %10 ]
%16 = call i32 @write(i32 %1, i8* %4, i32 %15)
%17 = call i32 @read(i32 %6, i8* %4, i32 2048)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %14, label %19
19: ; preds = %14, %10
%20 = tail call i32 @close(i32 %6)
br label %21
21: ; preds = %19, %8
ret void
}