#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 ringbuf {
  int dummy;
};

/* Variables and functions */
unsigned char ringbuf_sneak(struct ringbuf *, int);
void extractdata(struct ringbuf *buf, int size, int headerlen, int footerlen,
                 int steplen, unsigned char *databuf, int *datasize) {
  int src, dest;
  dest = 0;
  for (src = headerlen; src < size - footerlen; src += steplen)
    databuf[dest++] = ringbuf_sneak(buf, src);
  *datasize = dest;
}


x86 assembly (clang, -O0):
<extractdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1180 <extractdata+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <ringbuf_sneak@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    113e <extractdata+0x2e>
mov    -0x28(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x40(%rsp),%rax
sub    %ecx,%ebp
xor    %r13d,%r13d
cmp    %edx,%ebp
jle    115e <extractdata+0x4e>
mov    %r9,%r14
mov    %r8d,%r15d
mov    %edx,%ebx
mov    %rdi,%r12
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <ringbuf_sneak@plt>
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
add    %r15d,%ebx
cmp    %ebp,%ebx
jl     1140 <extractdata+0x30>
mov    0x40(%rsp),%rax
mov    %r13d,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ringbuf = type { i32 }
define void @extractdata(%struct.ringbuf* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5, i32* %6) {
%8 = alloca %struct.ringbuf*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
store %struct.ringbuf* %0, %struct.ringbuf** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32* %6, i32** %14
store i32 0, i32* %16
%17 = load i32, i32* %10
store i32 %17, i32* %15
br label %18
18: ; preds = %33, %7
%19 = load i32, i32* %15
%20 = load i32, i32* %9
%21 = load i32, i32* %11
%22 = sub nsw i32 %20, %21
%23 = icmp slt i32 %19, %22
br i1 %23, label %24, label %37
24: ; preds = %18
%25 = load %struct.ringbuf*, %struct.ringbuf** %8
%26 = load i32, i32* %15
%27 = call zeroext i8 @ringbuf_sneak(%struct.ringbuf* %25, i32 %26)
%28 = load i8*, i8** %13
%29 = load i32, i32* %16
%30 = add nsw i32 %29, 1
store i32 %30, i32* %16
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %12
%35 = load i32, i32* %15
%36 = add nsw i32 %35, %34
store i32 %36, i32* %15
br label %18
37: ; preds = %18
%38 = load i32, i32* %16
%39 = load i32*, i32** %14
store i32 %38, i32* %39
ret void
}

LLVM IR (-O2):
%struct.ringbuf = type { i32 }
define void @extractdata(%struct.ringbuf* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* nocapture writeonly %5, i32* nocapture writeonly %6) {
%8 = sub nsw i32 %1, %3
%9 = icmp sgt i32 %8, %2
br i1 %9, label %10, label %20
10: ; preds = %7, %10
%11 = phi i64 [ %14, %10 ], [ 0, %7 ]
%12 = phi i32 [ %16, %10 ], [ %2, %7 ]
%13 = tail call zeroext i8 @ringbuf_sneak(%struct.ringbuf* %0, i32 %12)
%14 = add nuw i64 %11, 1
%15 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 %13, i8* %15
%16 = add nsw i32 %12, %4
%17 = icmp slt i32 %16, %8
br i1 %17, label %10, label %18
18: ; preds = %10
%19 = trunc i64 %14 to i32
br label %20
20: ; preds = %18, %7
%21 = phi i32 [ 0, %7 ], [ %19, %18 ]
store i32 %21, i32* %6
ret void
}