#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *finp, *fout;
  int ich, nch, nline;
  char buf[82];
  if (argc < 3) {
    printf("usage fixlen inpfile outfile");
    exit(1);
  }
  finp = fopen(argv[1], "r");
  if (finp == NULL) {
    printf("bad input file: %s\n", argv[1]);
    exit(1);
  }
  fout = fopen(argv[2], "w");
  if (fout == NULL) {
    printf("bad output file: %s\n", argv[2]);
    exit(1);
  }
  nch = nline = 0;
  buf[80] = '\n';
  buf[81] = 0;
  while ((ich = getc(finp)) > 0) {
    if (ich == '\n') {
      for (; nch < 80; ++nch)
        buf[nch] = ' ';
      fputs(buf, fout);
      nch = 0;
      ++nline;
    } else if (nch < 80 && ich >= 32) {
      buf[nch] = ich;
      ++nch;
    }
  }
  fclose(finp);
  fclose(fout);
  printf("%d lines\n", nline);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119b <main+0x3b>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe73(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11de <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0xa,-0x30(%rbp)
movb   $0x0,-0x2f(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    12d2 <main+0x172>
cmpl   $0xa,-0x24(%rbp)
jne    129e <main+0x13e>
jmp    125b <main+0xfb>
cmpl   $0x50,-0x28(%rbp)
jge    127c <main+0x11c>
movslq -0x28(%rbp),%rax
movb   $0x20,-0x80(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    125b <main+0xfb>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12cd <main+0x16d>
cmpl   $0x50,-0x28(%rbp)
jge    12c8 <main+0x168>
cmpl   $0x20,-0x24(%rbp)
jl     12c8 <main+0x168>
mov    -0x24(%rbp),%eax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12cd <main+0x16d>
jmp    1237 <main+0xd7>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
cmp    $0x2,%edi
jle    1274 <main+0x104>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     128c <main+0x11c>
mov    %rax,%r12
mov    0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1299 <main+0x129>
mov    %rax,%r14
movw   $0xa,0x50(%rsp)
mov    %r12,%rdi
call   1090 <getc@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    1245 <main+0xd5>
mov    %rsp,%r15
xor    %ebx,%ebx
jmp    11fc <main+0x8c>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
add    $0x1,%ebp
xor    %ebx,%ebx
mov    %r12,%rdi
call   1090 <getc@plt>
test   %eax,%eax
jle    1245 <main+0xd5>
cmp    $0xa,%eax
jne    1230 <main+0xc0>
cmp    $0x4f,%ebx
jg     11e0 <main+0x70>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
mov    $0x4f,%edx
sub    %ebx,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1060 <memset@plt>
jmp    11e0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x4f,%ebx
jg     11f0 <main+0x80>
cmp    $0x20,%eax
jb     11f0 <main+0x80>
movslq %ebx,%rcx
mov    %al,(%rsp,%rcx,1)
add    $0x1,%ebx
jmp    11f0 <main+0x80>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xdee(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rbp),%rsi
lea    0xd88(%rip),%rdi
jmp    12a4 <main+0x134>
mov    0x10(%rbp),%rsi
lea    0xd91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"usage fixlen inpfile outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"bad input file: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"bad output file: %s\0A\00"
@.str.5 = [10 x i8] c"%d lines\0A\00"
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 i32
%10 = alloca i32
%11 = alloca [82 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
store i32 0, i32* %10
store i32 0, i32* %9
%44 = getelementptr inbounds [82 x i8], [82 x i8]* %11, i64 0, i64 80
store i8 10, i8* %44
%45 = getelementptr inbounds [82 x i8], [82 x i8]* %11, i64 0, i64 81
store i8 0, i8* %45
br label %46
46: ; preds = %85, %43
%47 = load i32*, i32** %6
%48 = call i32 @getc(i32* %47)
store i32 %48, i32* %8
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %86
50: ; preds = %46
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %70
53: ; preds = %50
br label %54
54: ; preds = %61, %53
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 80
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [82 x i8], [82 x i8]* %11, i64 0, i64 %59
store i8 32, i8* %60
br label %61
61: ; preds = %57
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %54
64: ; preds = %54
%65 = getelementptr inbounds [82 x i8], [82 x i8]* %11, i64 0, i64 0
%66 = load i32*, i32** %7
%67 = call i32 @fputs(i8* %65, i32* %66)
store i32 0, i32* %9
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %85
70: ; preds = %50
%71 = load i32, i32* %9
%72 = icmp slt i32 %71, 80
br i1 %72, label %73, label %84
73: ; preds = %70
%74 = load i32, i32* %8
%75 = icmp sge i32 %74, 32
br i1 %75, label %76, label %84
76: ; preds = %73
%77 = load i32, i32* %8
%78 = trunc i32 %77 to i8
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [82 x i8], [82 x i8]* %11, i64 0, i64 %80
store i8 %78, i8* %81
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
br label %84
84: ; preds = %76, %73, %70
br label %85
85: ; preds = %84, %64
br label %46
86: ; preds = %46
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
%89 = load i32*, i32** %7
%90 = call i32 @fclose(i32* %89)
%91 = load i32, i32* %10
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %91)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"usage fixlen inpfile outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"bad input file: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"bad output file: %s\0A\00"
@.str.5 = [10 x i8] c"%d lines\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [82 x i8]
%4 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%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* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 80
store i8 10, i8* %28
%29 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 81
store i8 0, i8* %29
%30 = tail call i32 @getc(i32* %12)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %27, %56
%33 = phi i32 [ %59, %56 ], [ %30, %27 ]
%34 = phi i32 [ %58, %56 ], [ 0, %27 ]
%35 = phi i32 [ %57, %56 ], [ 0, %27 ]
%36 = icmp eq i32 %33, 10
%37 = icmp slt i32 %35, 80
br i1 %36, label %38, label %48
38: ; preds = %32
br i1 %37, label %39, label %45
39: ; preds = %38
%40 = sext i32 %35 to i64
%41 = getelementptr [82 x i8], [82 x i8]* %3, i64 0, i64 %40
%42 = sub i32 79, %35
%43 = zext i32 %42 to i64
%44 = add nuw nsw i64 %43, 1
br label %45
45: ; preds = %39, %38
%46 = call i32 @fputs(i8* %4, i32* %21)
%47 = add nsw i32 %34, 1
br label %56
48: ; preds = %32
%49 = icmp ugt i32 %33, 31
%50 = and i1 %37, %49
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = trunc i32 %33 to i8
%53 = sext i32 %35 to i64
%54 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 %53
store i8 %52, i8* %54
%55 = add nsw i32 %35, 1
br label %56
56: ; preds = %48, %51, %45
%57 = phi i32 [ 0, %45 ], [ %55, %51 ], [ %35, %48 ]
%58 = phi i32 [ %47, %45 ], [ %34, %51 ], [ %34, %48 ]
%59 = tail call i32 @getc(i32* %12)
%60 = icmp sgt i32 %59, 0
br i1 %60, label %32, label %61
61: ; preds = %56, %27
%62 = phi i32 [ 0, %27 ], [ %58, %56 ]
%63 = tail call i32 @fclose(i32* %12)
%64 = tail call i32 @fclose(i32* %21)
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %62)
ret i32 0
}