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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int /*<<< orphan*/, char *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  long j;
  int i, r;
  int ch;
  FILE *si, *so;
  if (argc != 2) {
    fprintf(stderr, "%s: Usage %s [number]\n", argv[0], argv[0]);
    exit(1);
  }
  r = atoi(argv[1]);
  si = fdopen(fileno(stdin), "rb");
  so = fdopen(fileno(stdout), "wb");
  if (fseek(si, 0L, SEEK_END))
    perror(argv[0]);
  for (j = ftell(si) / r - 1; j >= 0; j--) {
    if (fseek(si, j * r, SEEK_SET))
      perror(argv[0]);
    for (i = 0; i < r; i++) {
      ch = fgetc(si);
      fputc(ch, so);
    }
  }
  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   $0x2,-0x8(%rbp)
je     11ed <main+0x4d>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    0xe03(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    0xde6(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     1269 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
cltd
idivl  -0x20(%rbp)
sub    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     130d <main+0x16d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
imul   %rax,%rsi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     12be <main+0x11e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12f7 <main+0x157>
mov    -0x30(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c5 <main+0x125>
jmp    12fc <main+0x15c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    127f <main+0xdf>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x2,%edi
jne    12db <main+0x13b>
mov    0x8(%r15),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
lea    0xe3f(%rip),%rsi
mov    %eax,%edi
call   1090 <fdopen@plt>
mov    %rax,%rbx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
lea    0xe23(%rip),%rsi
mov    %eax,%edi
call   1090 <fdopen@plt>
mov    %rax,%rbp
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    12ce <main+0x12e>
mov    %r15,(%rsp)
mov    %rbx,%rdi
call   1060 <ftell@plt>
cltd
idiv   %r14d
test   %eax,%eax
jle    12bd <main+0x11d>
mov    %eax,%r12d
add    $0xffffffff,%r12d
movslq %r14d,%r13
jmp    125d <main+0xbd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%r12),%rax
test   %r12,%r12
mov    %rax,%r12
jle    12bd <main+0x11d>
mov    %r12,%rsi
imul   %r13,%rsi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
test   %rax,%rax
jne    12aa <main+0x10a>
test   %r14d,%r14d
jle    1250 <main+0xb0>
mov    %r14d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0xffffffff,%r15d
jne    1290 <main+0xf0>
jmp    1250 <main+0xb0>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
test   %r14d,%r14d
jg     127f <main+0xdf>
jmp    1250 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rdi
call   10a0 <perror@plt>
jmp    121d <main+0x7d>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rcx
lea    0xd12(%rip),%rsi
mov    %rcx,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"%s: Usage %s [number]\0A\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%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, 2
br i1 %13, label %14, label %24
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 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* @stdin
%30 = call i32 @fileno(i32 %29)
%31 = call i32* @fdopen(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %10
%32 = load i32, i32* @stdout
%33 = call i32 @fileno(i32 %32)
%34 = call i32* @fdopen(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %11
%35 = load i32*, i32** %10
%36 = load i32, i32* @SEEK_END
%37 = call i64 @fseek(i32* %35, i64 0, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %24
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @perror(i8* %42)
br label %44
44: ; preds = %39, %24
%45 = load i32*, i32** %10
%46 = call i32 @ftell(i32* %45)
%47 = load i32, i32* %8
%48 = sdiv i32 %46, %47
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
store i64 %50, i64* %6
br label %51
51: ; preds = %83, %44
%52 = load i64, i64* %6
%53 = icmp sge i64 %52, 0
br i1 %53, label %54, label %86
54: ; preds = %51
%55 = load i32*, i32** %10
%56 = load i64, i64* %6
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = mul nsw i64 %56, %58
%60 = load i32, i32* @SEEK_SET
%61 = call i64 @fseek(i32* %55, i64 %59, i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %54
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @perror(i8* %66)
br label %68
68: ; preds = %63, %54
store i32 0, i32* %7
br label %69
69: ; preds = %79, %68
%70 = load i32, i32* %7
%71 = load i32, i32* %8
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %82
73: ; preds = %69
%74 = load i32*, i32** %10
%75 = call i32 @fgetc(i32* %74)
store i32 %75, i32* %9
%76 = load i32, i32* %9
%77 = load i32*, i32** %11
%78 = call i32 @fputc(i32 %76, i32* %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %69
82: ; preds = %69
br label %83
83: ; preds = %82
%84 = load i64, i64* %6
%85 = add nsw i64 %84, -1
store i64 %85, i64* %6
br label %51
86: ; preds = %51
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"%s: Usage %s [number]\0A\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = load i32, i32* @stdin
%14 = tail call i32 @fileno(i32 %13)
%15 = tail call i32* @fdopen(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = tail call i32 @fileno(i32 %16)
%18 = tail call i32* @fdopen(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @SEEK_END
%20 = tail call i64 @fseek(i32* %15, i64 0, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %9
%23 = load i8*, i8** %1
%24 = tail call i32 @perror(i8* %23)
br label %25
25: ; preds = %22, %9
%26 = tail call i32 @ftell(i32* %15)
%27 = sdiv i32 %26, %12
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %53
29: ; preds = %25
%30 = add nsw i32 %27, -1
%31 = zext i32 %30 to i64
%32 = sext i32 %12 to i64
%33 = icmp sgt i32 %12, 0
br label %34
34: ; preds = %29, %50
%35 = phi i64 [ %31, %29 ], [ %51, %50 ]
%36 = mul nsw i64 %35, %32
%37 = load i32, i32* @SEEK_SET
%38 = tail call i64 @fseek(i32* %15, i64 %36, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i8*, i8** %1
%42 = tail call i32 @perror(i8* %41)
br label %43
43: ; preds = %40, %34
br i1 %33, label %44, label %50
44: ; preds = %43, %44
%45 = phi i32 [ %48, %44 ], [ 0, %43 ]
%46 = tail call i32 @fgetc(i32* %15)
%47 = tail call i32 @fputc(i32 %46, i32* %18)
%48 = add nuw nsw i32 %45, 1
%49 = icmp eq i32 %48, %12
br i1 %49, label %50, label %44
50: ; preds = %44, %43
%51 = add nsw i64 %35, -1
%52 = icmp sgt i64 %35, 0
br i1 %52, label %34, label %53
53: ; preds = %50, %25
ret i32 0
}