#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, size_t);
size_t strtoull(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ system(char *);
int main() {
  char buf[32] = "";
  system("/bin/echo 'addr?'");
  read(STDIN_FILENO, buf, sizeof(buf));
  char *addr = (char *)strtoull(buf, NULL, 16);
  system("/bin/echo 'len?'");
  read(STDIN_FILENO, buf, sizeof(buf));
  size_t len = strtoull(buf, NULL, 16);
  system("/bin/echo 'data?'");
  read(STDIN_FILENO, addr, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xe9a(%rip),%rdi
call   1030 <system@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,-0x38(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <system@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,-0x40(%rbp)
lea    0xe4b(%rip),%rdi
call   1030 <system@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1050 <read@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xeb4(%rip),%rdi
call   1030 <system@plt>
mov    0x2e88(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%rbx
mov    $0x20,%edx
mov    %rbx,%rsi
call   1040 <read@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoull@plt>
mov    %rax,%r14
lea    0xe8e(%rip),%rdi
call   1030 <system@plt>
mov    (%r15),%edi
mov    $0x20,%edx
mov    %rbx,%rsi
call   1040 <read@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoull@plt>
mov    %rax,%rbx
lea    0xe71(%rip),%rdi
call   1030 <system@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <read@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/bin/echo 'addr?'\00"
@STDIN_FILENO = global i32 0
@.str.1 = [17 x i8] c"/bin/echo 'len?'\00"
@.str.2 = [18 x i8] c"/bin/echo 'data?'\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i8*
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast [32 x i8]* %2 to i8*
%6 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @STDIN_FILENO
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i64 32)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%11 = call i64 @strtoull(i8* %10, i32* null, i32 16)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @STDIN_FILENO
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i64 32)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%18 = call i64 @strtoull(i8* %17, i32* null, i32 16)
store i64 %18, i64* %4
%19 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @STDIN_FILENO
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = call i32 @read(i32 %20, i8* %21, i64 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"/bin/echo 'addr?'\00"
@STDIN_FILENO = global i32 0
@.str.1 = [17 x i8] c"/bin/echo 'len?'\00"
@.str.2 = [18 x i8] c"/bin/echo 'data?'\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @read(i32 %4, i8* %2, i64 32)
%6 = call i64 @strtoull(i8* nocapture %2, i32* null, i32 16)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @read(i32 %9, i8* %2, i64 32)
%11 = call i64 @strtoull(i8* nocapture %2, i32* null, i32 16)
%12 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @STDIN_FILENO
%14 = tail call i32 @read(i32 %13, i8* %7, i64 %11)
ret i32 0
}