#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 */
struct nf2device {
  int dummy;
};

/* Variables and functions */
unsigned int ntohl(unsigned int);
int /*<<< orphan*/ readReg(struct nf2device *, unsigned int, unsigned int *);
void readStr(struct nf2device *nf2, unsigned regStart, unsigned len,
             char *dst) {
  int i;
  for (i = 0; i < len / 4; i++) {
    readReg(nf2, regStart + i * 4, (unsigned *)(dst + i * 4));
    *(unsigned *)(dst + i * 4) = ntohl(*(unsigned *)(dst + i * 4));
  }
  dst[(len / 4) * 4 - 1] = '\0';
}


x86 assembly (clang, -O0):
<readStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%ecx
shr    $0x2,%ecx
cmp    %ecx,%eax
jae    11a6 <readStr+0x86>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
add    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rdx
call   1030 <readReg@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%edi
call   1040 <ntohl@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <readStr+0x1d>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
shr    $0x2,%ecx
shl    $0x2,%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readStr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
cmp    $0x4,%edx
jb     1173 <readStr+0x53>
mov    %esi,%ebp
mov    %rdi,%r12
mov    %r15d,%r13d
shr    $0x2,%r13d
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <readReg@plt>
mov    (%rbx),%edi
call   1040 <ntohl@plt>
mov    %eax,(%rbx)
add    $0x4,%rbx
add    $0x4,%ebp
add    $0xffffffffffffffff,%r13
jne    1150 <readStr+0x30>
and    $0xfffffffc,%r15d
add    $0xffffffff,%r15d
movb   $0x0,(%r14,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nf2device = type { i32 }
define void @readStr(%struct.nf2device* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca %struct.nf2device*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store %struct.nf2device* %0, %struct.nf2device** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %42, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = udiv i32 %12, 4
%14 = icmp ult i32 %11, %13
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = load %struct.nf2device*, %struct.nf2device** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %9
%19 = mul nsw i32 %18, 4
%20 = add i32 %17, %19
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = mul nsw i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = bitcast i8* %25 to i32*
%27 = call i32 @readReg(%struct.nf2device* %16, i32 %20, i32* %26)
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = mul nsw i32 %29, 4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = bitcast i8* %32 to i32*
%34 = load i32, i32* %33
%35 = call i32 @ntohl(i32 %34)
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = mul nsw i32 %37, 4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = bitcast i8* %40 to i32*
store i32 %35, i32* %41
br label %42
42: ; preds = %15
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %10
45: ; preds = %10
%46 = load i8*, i8** %8
%47 = load i32, i32* %7
%48 = udiv i32 %47, 4
%49 = mul i32 %48, 4
%50 = sub i32 %49, 1
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %46, i64 %51
store i8 0, i8* %52
ret void
}

LLVM IR (-O2):
%struct.nf2device = type { i32 }
define void @readStr(%struct.nf2device* %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp ult i32 %2, 4
br i1 %5, label %21, label %6
6: ; preds = %4
%7 = lshr i32 %2, 2
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %19, %9 ]
%11 = shl nsw i64 %10, 2
%12 = trunc i64 %11 to i32
%13 = add i32 %12, %1
%14 = getelementptr inbounds i8, i8* %3, i64 %11
%15 = bitcast i8* %14 to i32*
%16 = tail call i32 @readReg(%struct.nf2device* %0, i32 %13, i32* %15)
%17 = load i32, i32* %15
%18 = tail call i32 @ntohl(i32 %17)
store i32 %18, i32* %15
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9, %4
%22 = and i32 %2, -4
%23 = add i32 %22, -1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %3, i64 %24
store i8 0, i8* %25
ret void
}