#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 */
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ get(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ put(char, int);
int /*<<< orphan*/ twiddle();
int transfer(int fd, FILE *dump, int ramend) {
  int n;
  put('D', fd);
  printf("reading mem: ");
  for (n = 0; n <= ramend; n++) {
    twiddle();
    fputc(get(fd), dump);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x44,%edi
call   1030 <put@plt>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11b6 <transfer+0x66>
mov    $0x0,%al
call   1070 <twiddle@plt>
mov    -0x4(%rbp),%edi
call   1060 <get@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <transfer+0x32>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x44,%edi
mov    %ebp,%esi
call   1040 <put@plt>
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
test   %ebx,%ebx
js     11ad <transfer+0x4d>
add    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <twiddle@plt>
mov    %ebp,%edi
call   1070 <get@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
add    $0xffffffff,%ebx
jne    1190 <transfer+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"reading mem: \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @transfer(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = call i32 @put(i8 signext 68, i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %11
11: ; preds = %21, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = call i32 (...) @twiddle()
%17 = load i32, i32* %4
%18 = call i32 @get(i32 %17)
%19 = load i32*, i32** %5
%20 = call i32 @fputc(i32 %18, i32* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %11
24: ; preds = %11
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"reading mem: \00"
define i32 @transfer(i32 %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @put(i8 signext 68, i32 %0)
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i32 %2, 0
br i1 %6, label %14, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %12, %7 ], [ 0, %3 ]
%9 = tail call i32 (...) @twiddle()
%10 = tail call i32 @get(i32 %0)
%11 = tail call i32 @fputc(i32 %10, i32* %1)
%12 = add nuw i32 %8, 1
%13 = icmp eq i32 %8, %2
br i1 %13, label %14, label %7
14: ; preds = %7, %3
%15 = tail call i32 @putchar(i32 10)
ret i32 0
}