#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 */
int BUFSIZ;
int atoi(char *);
int fgetl(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "usage: %s mod offset < infile > outfile\n", argv[0]);
    return (-1);
  }
  const int mod = atoi(argv[1]);
  if (mod < 1) {
    fprintf(stderr, "mod < 1\n");
    return (-1);
  }
  const int offset = atoi(argv[2]);
  if (offset >= mod) {
    fprintf(stderr, "offset >= mod\n");
    return (-1);
  }
  int pos = 0;
  char line_buf[BUFSIZ];
  int line_len;
  while ((line_len = fgetl(stdin, BUFSIZ, line_buf)) != -1) {
    if (line_len == 0)
      continue;
    if (pos == mod)
      pos = 0;
    if ((pos++ % mod) != offset)
      continue;
    puts(line_buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118a <main+0x4a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <main+0x17b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11c7 <main+0x87>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <main+0x17b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1206 <main+0xc6>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <main+0x17b>
movl   $0x0,-0x1c(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdx
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
call   1050 <fgetl@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     12ad <main+0x16d>
cmpl   $0x0,-0x34(%rbp)
jne    126f <main+0x12f>
jmp    1239 <main+0xf9>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1282 <main+0x142>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltd
idivl  -0x14(%rbp)
cmp    -0x18(%rbp),%edx
je     129f <main+0x15f>
jmp    1239 <main+0xf9>
mov    -0x40(%rbp),%rdi
call   1030 <puts@plt>
jmp    1239 <main+0xf9>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11ee <main+0xae>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    120f <main+0xcf>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
cmp    %r15d,%eax
jge    1221 <main+0xe1>
mov    %eax,-0x2c(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2e3f(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e3b(%rip),%r12
xor    %r14d,%r14d
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    %rbx,%rdx
call   1050 <fgetl@plt>
test   %eax,%eax
je     11b0 <main+0x70>
cmp    $0xffffffff,%eax
je     123f <main+0xff>
cmp    %r15d,%r14d
mov    %r14d,%eax
mov    $0x0,%ecx
cmove  %ecx,%eax
lea    0x1(%rax),%r14d
cltd
idiv   %r15d
cmp    -0x2c(%rbp),%edx
jne    11b0 <main+0x70>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x70>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1245 <main+0x105>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
jmp    1231 <main+0xf1>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1245 <main+0x105>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"usage: %s mod offset < infile > outfile\0A\00"
@.str.1 = [9 x i8] c"mod < 1\0A\00"
@.str.2 = [15 x i8] c"offset >= mod\0A\00"
@BUFSIZ = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %72
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = icmp sge i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
41: ; preds = %30
store i32 0, i32* %8
%42 = load i32, i32* @BUFSIZ
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %9
%45 = alloca i8, i64 %43
store i64 %43, i64* %10
br label %46
46: ; preds = %68, %67, %54, %41
%47 = load i32, i32* @stdin
%48 = load i32, i32* @BUFSIZ
%49 = call i32 @fgetl(i32 %47, i32 %48, i8* %45)
store i32 %49, i32* %11
%50 = icmp ne i32 %49, -1
br i1 %50, label %51, label %70
51: ; preds = %46
%52 = load i32, i32* %11
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
br label %46
55: ; preds = %51
%56 = load i32, i32* %8
%57 = load i32, i32* %6
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 0, i32* %8
br label %60
60: ; preds = %59, %55
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
%63 = load i32, i32* %6
%64 = srem i32 %61, %63
%65 = load i32, i32* %7
%66 = icmp ne i32 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %60
br label %46
68: ; preds = %60
%69 = call i32 @puts(i8* %45)
br label %46
70: ; preds = %46
store i32 0, i32* %3
%71 = load i8*, i8** %9
br label %72
72: ; preds = %70, %38, %27, %14
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"usage: %s mod offset < infile > outfile\0A\00"
@.str.1 = [9 x i8] c"mod < 1\0A\00"
@.str.2 = [15 x i8] c"offset >= mod\0A\00"
@BUFSIZ = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %45
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %45
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp slt i32 %19, %11
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %45
24: ; preds = %16
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = tail call i8* @llvm.stacksave()
%28 = alloca i8, i64 %26
br label %29
29: ; preds = %41, %24
%30 = phi i32 [ 0, %24 ], [ %38, %41 ]
br label %31
31: ; preds = %29, %31
%32 = load i32, i32* @stdin
%33 = load i32, i32* @BUFSIZ
%34 = call i32 @fgetl(i32 %32, i32 %33, i8* %28)
switch i32 %34, label %35 [
i32 -1, label %44
i32 0, label %31
]
35: ; preds = %31
%36 = icmp eq i32 %30, %11
%37 = select i1 %36, i32 0, i32 %30
%38 = add nsw i32 %37, 1
%39 = srem i32 %37, %11
%40 = icmp eq i32 %39, %19
br i1 %40, label %42, label %41
41: ; preds = %35, %42
br label %29
42: ; preds = %35
%43 = call i32 @puts(i8* %28)
br label %41
44: ; preds = %31
br label %45
45: ; preds = %13, %44, %21, %4
%46 = phi i32 [ -1, %4 ], [ -1, %13 ], [ -1, %21 ], [ 0, %44 ]
ret i32 %46
}