#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 */
unsigned int get_word();
int /*<<< orphan*/ put_char(unsigned char);
void read_block(void) {
  unsigned char checksum = 0;
  unsigned char *p = (unsigned char *)get_word();
  unsigned length = get_word();
  while (length--) {
    put_char(*p);
    checksum += *p++;
  }
  put_char(checksum);
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x0,-0x1(%rbp)
mov    $0x0,%al
call   1040 <get_word@plt>
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <get_word@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1183 <read_block+0x63>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <put_char@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%ecx
movzbl -0x1(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x1(%rbp)
jmp    1143 <read_block+0x23>
movzbl -0x1(%rbp),%edi
call   1030 <put_char@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <get_word@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <get_word@plt>
test   %eax,%eax
je     1167 <read_block+0x47>
mov    %ebx,%r15d
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edi
call   1030 <put_char@plt>
add    (%r15,%rbx,1),%bpl
add    $0x1,%rbx
cmp    %ebx,%r14d
jne    1150 <read_block+0x30>
movzbl %bpl,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <put_char@plt>

LLVM IR (-O0):
define void @read_block() {
%1 = alloca i8
%2 = alloca i8*
%3 = alloca i32
store i8 0, i8* %1
%4 = call i32 (...) @get_word()
%5 = zext i32 %4 to i64
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = call i32 (...) @get_word()
store i32 %7, i32* %3
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* %3
%10 = add i32 %9, -1
store i32 %10, i32* %3
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = call i32 @put_char(i8 zeroext %14)
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = load i8, i8* %1
%21 = zext i8 %20 to i32
%22 = add nsw i32 %21, %19
%23 = trunc i32 %22 to i8
store i8 %23, i8* %1
br label %8
24: ; preds = %8
%25 = load i8, i8* %1
%26 = call i32 @put_char(i8 zeroext %25)
ret void
}

LLVM IR (-O2):
define void @read_block() {
%1 = tail call i32 (...) @get_word()
%2 = tail call i32 (...) @get_word()
%3 = icmp eq i32 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %0
%5 = zext i32 %1 to i64
%6 = inttoptr i64 %5 to i8*
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ %11, %7 ], [ %2, %4 ]
%9 = phi i8* [ %14, %7 ], [ %6, %4 ]
%10 = phi i8 [ %16, %7 ], [ 0, %4 ]
%11 = add i32 %8, -1
%12 = load i8, i8* %9
%13 = tail call i32 @put_char(i8 zeroext %12)
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = load i8, i8* %9
%16 = add i8 %15, %10
%17 = icmp eq i32 %11, 0
br i1 %17, label %18, label %7
18: ; preds = %7, %0
%19 = phi i8 [ 0, %0 ], [ %16, %7 ]
%20 = tail call i32 @put_char(i8 zeroext %19)
ret void
}