#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 uint;
struct dinode {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ iappend(int, char *, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int readi(struct dinode *, char *, int, int);
void copy_dinode_content(struct dinode *src, uint dst) {
  char buf[512];
  char *cbuf = (char *)buf;
  uint n = sizeof(buf);
  uint off = 0;
  uint r;
  memset((void *)cbuf, 0, n);
  while ((r = readi(src, cbuf, off, n)) > 0) {
    off += r;
    iappend(dst, cbuf, r);
    memset((void *)cbuf, 0, n);
  }
}


x86 assembly (clang, -O0):
<copy_dinode_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
movl   $0x200,-0x21c(%rbp)
movl   $0x0,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
mov    -0x21c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x218(%rbp),%rsi
mov    -0x220(%rbp),%edx
mov    -0x21c(%rbp),%ecx
call   1050 <readi@plt>
mov    %eax,-0x224(%rbp)
cmp    $0x0,%eax
jle    11e3 <copy_dinode_content+0xb3>
mov    -0x224(%rbp),%eax
add    -0x220(%rbp),%eax
mov    %eax,-0x220(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x218(%rbp),%rsi
mov    -0x224(%rbp),%edx
call   1030 <iappend@plt>
mov    -0x218(%rbp),%rdi
mov    -0x21c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    1178 <copy_dinode_content+0x48>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_dinode_content>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x200,%ecx
call   1050 <readi@plt>
test   %eax,%eax
jle    11a4 <copy_dinode_content+0x74>
mov    %rsp,%rbx
add    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <iappend@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    $0x200,%ecx
call   1050 <readi@plt>
test   %eax,%eax
jg     1170 <copy_dinode_content+0x40>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dinode = type { i32 }
define void @copy_dinode_content(%struct.dinode* %0, i32 %1) {
%3 = alloca %struct.dinode*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.dinode* %0, %struct.dinode** %3
store i32 %1, i32* %4
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
store i8* %10, i8** %6
store i32 512, i32* %7
store i32 0, i32* %8
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @memset(i8* %11, i32 0, i32 %12)
br label %14
14: ; preds = %21, %2
%15 = load %struct.dinode*, %struct.dinode** %3
%16 = load i8*, i8** %6
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = call i32 @readi(%struct.dinode* %15, i8* %16, i32 %17, i32 %18)
store i32 %19, i32* %9
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %14
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = add nsw i32 %23, %22
store i32 %24, i32* %8
%25 = load i32, i32* %4
%26 = load i8*, i8** %6
%27 = load i32, i32* %9
%28 = call i32 @iappend(i32 %25, i8* %26, i32 %27)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = call i32 @memset(i8* %29, i32 0, i32 %30)
br label %14
32: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.dinode = type { i32 }
define void @copy_dinode_content(%struct.dinode* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 512)
%6 = call i32 @readi(%struct.dinode* %0, i8* %4, i32 0, i32 512)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ %6, %2 ]
%10 = phi i32 [ %11, %8 ], [ 0, %2 ]
%11 = add nsw i32 %9, %10
%12 = call i32 @iappend(i32 %1, i8* %4, i32 %9)
%13 = call i32 @memset(i8* %4, i32 0, i32 512)
%14 = call i32 @readi(%struct.dinode* %0, i8* %4, i32 %11, i32 512)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %8, label %16
16: ; preds = %8, %2
ret void
}