#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 stat {
  int st_size;
};
typedef int off_t;
typedef int /*<<< orphan*/ header;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
unsigned char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ unsquash(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char **argv) {
  char *infile, *outfile;
  int ifd, ofd;
  unsigned char temp;
  int linelength, lines;
  struct stat finfo;
  unsigned char *inbuf, *outbuf;
  unsigned char header[6];
  off_t imagesize;
  if (argc != 3) {
    usage(argv[0]);
    return 1;
  }
  infile = argv[1];
  outfile = argv[2];
  ifd = open(infile, O_RDONLY);
  if (ifd < 0) {
    perror("could not open infile");
    return 1;
  }
  ofd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, 00644);
  if (ofd < 0) {
    perror("could not open outfile");
    close(ifd);
    return 1;
  }
  read(ifd, &temp, 1);
  linelength = temp << 8;
  read(ifd, &temp, 1);
  linelength |= temp & 0xff;
  lseek(ifd, 4, SEEK_CUR);
  if ((linelength < 0) || (linelength > 720)) {
    printf("invalid linelength %d", linelength);
    return 1;
  }
  inbuf = malloc(linelength);
  if (!inbuf) {
    perror("out of memory");
    close(ofd);
    close(ifd);
    return 1;
  }
  outbuf = malloc(linelength * 2);
  if (!outbuf) {
    perror("out of memory");
    free(inbuf);
    close(ofd);
    close(ifd);
    return 1;
  }
  fstat(ifd, &finfo);
  imagesize = finfo.st_size - sizeof(header);
  lines = imagesize / linelength;
  if (!lines) {
    perror("linesize bigger than file");
    free(inbuf);
    free(outbuf);
    close(ofd);
    close(ifd);
    return 1;
  }
  if (imagesize % linelength) {
    printf("Warning: file does not fit to linelength, %ld excess bytes\n",
           imagesize % linelength);
  }
  printf("unsquashing %d lines now\n", lines);
  header[0] = (linelength & 0xff00) >> 8;
  header[1] = (linelength & 0xff);
  header[2] = (lines & 0xff00) >> 8;
  header[3] = (lines & 0xff);
  header[4] = 0x00;
  header[5] = 0x00;
  write(ofd, header, sizeof(header));
  while (lines--) {
    read(ifd, inbuf, linelength);
    unsquash(inbuf, outbuf, linelength);
    write(ofd, outbuf, linelength * 2);
  }
  free(inbuf);
  free(outbuf);
  close(ifd);
  close(ofd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1249 <main+0x89>
lea    0xdc8(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x20(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d9b(%rip),%rax
or     (%rax),%esi
mov    0x2d8a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12a1 <main+0xe1>
lea    0xd8e(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x24(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl -0x29(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl -0x29(%rbp),%eax
and    $0xff,%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <lseek@plt>
cmpl   $0x0,-0x30(%rbp)
jl     1309 <main+0x149>
cmpl   $0x2d0,-0x30(%rbp)
jle    1324 <main+0x164>
mov    -0x30(%rbp),%esi
lea    0xd1a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x30(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1363 <main+0x1a3>
lea    0xd01(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x30(%rbp),%edi
shl    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    13ae <main+0x1ee>
lea    0xcbf(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10e0 <fstat@plt>
movslq -0x38(%rbp),%rax
sub    $0x6,%rax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1413 <main+0x253>
lea    0xc71(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1505 <main+0x345>
mov    -0x54(%rbp),%eax
cltd
idivl  -0x30(%rbp)
cmp    $0x0,%edx
je     1438 <main+0x278>
mov    -0x54(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %edx,%esi
lea    0xc38(%rip),%rdi
call   1050 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xc65(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x4e(%rbp)
mov    -0x30(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x4d(%rbp)
mov    -0x34(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x4c(%rbp)
mov    -0x34(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x4b(%rbp)
movb   $0x0,-0x4a(%rbp)
movb   $0x0,-0x49(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x4e(%rbp),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x34(%rbp)
cmp    $0x0,%eax
je     14dc <main+0x31c>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1080 <read@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   10a0 <unsquash@plt>
mov    -0x28(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%edx
shl    $0x1,%edx
call   1040 <write@plt>
jmp    1492 <main+0x2d2>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x3,%edi
jne    129f <main+0xdf>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     13d2 <main+0x212>
mov    %eax,%r15d
mov    0x2dd7(%rip),%rax
mov    0x2df0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ddd(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     13e3 <main+0x223>
mov    %eax,%r13d
lea    0x3(%rsp),%r14
mov    $0x1,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl 0x3(%rsp),%r12d
mov    %r12d,%ebp
shl    $0x8,%ebp
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl 0x3(%rsp),%r14d
or     %r14d,%ebp
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    $0x4,%esi
call   1060 <lseek@plt>
cmp    $0x2d1,%ebp
jb     12b1 <main+0xf1>
lea    0xd9a(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
jmp    13c1 <main+0x201>
mov    (%rsi),%rdi
call   10b0 <usage@plt>
mov    $0x1,%ebx
jmp    13c1 <main+0x201>
mov    %r12d,0x1c(%rsp)
mov    %ebp,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     13f1 <main+0x231>
mov    %rax,%r12
mov    %r14d,0x18(%rsp)
mov    %r13d,0x4(%rsp)
lea    0x0(%rbp,%rbp,1),%r13d
mov    %r13d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1402 <main+0x242>
mov    %rax,%r14
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
call   10e0 <fstat@plt>
mov    0x10(%rsp),%eax
add    $0xfffffffa,%eax
cltd
idiv   %ebp
test   %eax,%eax
je     1413 <main+0x253>
mov    %eax,%ebx
mov    %r12,0x20(%rsp)
mov    %r13d,%r12d
mov    %r15d,%r13d
test   %edx,%edx
je     132a <main+0x16a>
lea    0xd48(%rip),%rdi
mov    %edx,%esi
call   1050 <printf@plt>
lea    0xd76(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    0x1c(%rsp),%eax
mov    %al,0xa(%rsp)
mov    0x18(%rsp),%eax
mov    %al,0xb(%rsp)
mov    %bh,0xc(%rsp)
mov    %bl,0xd(%rsp)
movw   $0x0,0xe(%rsp)
lea    0xa(%rsp),%rsi
mov    0x4(%rsp),%edi
mov    $0x6,%edx
call   1040 <write@plt>
mov    0x20(%rsp),%r15
nop
mov    %r13d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1080 <read@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10a0 <unsquash@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebx
jne    1370 <main+0x1b0>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc27(%rip),%rdi
call   10d0 <perror@plt>
jmp    12a7 <main+0xe7>
lea    0xc2c(%rip),%rdi
call   10d0 <perror@plt>
jmp    1438 <main+0x278>
lea    0xc4b(%rip),%rdi
call   10d0 <perror@plt>
mov    %r13d,%edi
jmp    1433 <main+0x273>
lea    0xc3a(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12,%rdi
jmp    142a <main+0x26a>
lea    0xc37(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
jmp    12a7 <main+0xe7>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [22 x i8] c"could not open infile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [23 x i8] c"could not open outfile\00"
@SEEK_CUR = global i32 0
@.str.2 = [22 x i8] c"invalid linelength %d\00"
@.str.3 = [14 x i8] c"out of memory\00"
@.str.4 = [26 x i8] c"linesize bigger than file\00"
@.str.5 = [60 x i8] c"Warning: file does not fit to linelength, %ld excess bytes\0A\00"
@.str.6 = [26 x i8] c"unsquashing %d lines now\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.stat
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca [6 x i8]
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @usage(i8* %23)
store i32 1, i32* %3
br label %188
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %7
%32 = load i8*, i8** %6
%33 = load i32, i32* @O_RDONLY
%34 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %188
39: ; preds = %25
%40 = load i8*, i8** %7
%41 = load i32, i32* @O_RDWR
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = load i32, i32* @O_TRUNC
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %45, i32 420)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %39
%50 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
store i32 1, i32* %3
br label %188
53: ; preds = %39
%54 = load i32, i32* %8
%55 = call i32 @read(i32 %54, i8* %10, i32 1)
%56 = load i8, i8* %10
%57 = zext i8 %56 to i32
%58 = shl i32 %57, 8
store i32 %58, i32* %11
%59 = load i32, i32* %8
%60 = call i32 @read(i32 %59, i8* %10, i32 1)
%61 = load i8, i8* %10
%62 = zext i8 %61 to i32
%63 = and i32 %62, 255
%64 = load i32, i32* %11
%65 = or i32 %64, %63
store i32 %65, i32* %11
%66 = load i32, i32* %8
%67 = load i32, i32* @SEEK_CUR
%68 = call i32 @lseek(i32 %66, i32 4, i32 %67)
%69 = load i32, i32* %11
%70 = icmp slt i32 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %53
%72 = load i32, i32* %11
%73 = icmp sgt i32 %72, 720
br i1 %73, label %74, label %77
74: ; preds = %71, %53
%75 = load i32, i32* %11
%76 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %75)
store i32 1, i32* %3
br label %188
77: ; preds = %71
%78 = load i32, i32* %11
%79 = call i8* @malloc(i32 %78)
store i8* %79, i8** %14
%80 = load i8*, i8** %14
%81 = icmp ne i8* %80, null
br i1 %81, label %88, label %82
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%84 = load i32, i32* %9
%85 = call i32 @close(i32 %84)
%86 = load i32, i32* %8
%87 = call i32 @close(i32 %86)
store i32 1, i32* %3
br label %188
88: ; preds = %77
%89 = load i32, i32* %11
%90 = mul nsw i32 %89, 2
%91 = call i8* @malloc(i32 %90)
store i8* %91, i8** %15
%92 = load i8*, i8** %15
%93 = icmp ne i8* %92, null
br i1 %93, label %102, label %94
94: ; preds = %88
%95 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%96 = load i8*, i8** %14
%97 = call i32 @free(i8* %96)
%98 = load i32, i32* %9
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* %8
%101 = call i32 @close(i32 %100)
store i32 1, i32* %3
br label %188
102: ; preds = %88
%103 = load i32, i32* %8
%104 = call i32 @fstat(i32 %103, %struct.stat* %13)
%105 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%106 = load i32, i32* %105
%107 = sext i32 %106 to i64
%108 = sub i64 %107, 6
%109 = trunc i64 %108 to i32
store i32 %109, i32* %17
%110 = load i32, i32* %17
%111 = load i32, i32* %11
%112 = sdiv i32 %110, %111
store i32 %112, i32* %12
%113 = load i32, i32* %12
%114 = icmp ne i32 %113, 0
br i1 %114, label %125, label %115
115: ; preds = %102
%116 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%117 = load i8*, i8** %14
%118 = call i32 @free(i8* %117)
%119 = load i8*, i8** %15
%120 = call i32 @free(i8* %119)
%121 = load i32, i32* %9
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* %8
%124 = call i32 @close(i32 %123)
store i32 1, i32* %3
br label %188
125: ; preds = %102
%126 = load i32, i32* %17
%127 = load i32, i32* %11
%128 = srem i32 %126, %127
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %135
130: ; preds = %125
%131 = load i32, i32* %17
%132 = load i32, i32* %11
%133 = srem i32 %131, %132
%134 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i32 %133)
br label %135
135: ; preds = %130, %125
%136 = load i32, i32* %12
%137 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %136)
%138 = load i32, i32* %11
%139 = and i32 %138, 65280
%140 = ashr i32 %139, 8
%141 = trunc i32 %140 to i8
%142 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 0
store i8 %141, i8* %142
%143 = load i32, i32* %11
%144 = and i32 %143, 255
%145 = trunc i32 %144 to i8
%146 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 1
store i8 %145, i8* %146
%147 = load i32, i32* %12
%148 = and i32 %147, 65280
%149 = ashr i32 %148, 8
%150 = trunc i32 %149 to i8
%151 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 2
store i8 %150, i8* %151
%152 = load i32, i32* %12
%153 = and i32 %152, 255
%154 = trunc i32 %153 to i8
%155 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 3
store i8 %154, i8* %155
%156 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 4
store i8 0, i8* %156
%157 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 5
store i8 0, i8* %157
%158 = load i32, i32* %9
%159 = getelementptr inbounds [6 x i8], [6 x i8]* %16, i64 0, i64 0
%160 = call i32 @write(i32 %158, i8* %159, i32 6)
br label %161
161: ; preds = %165, %135
%162 = load i32, i32* %12
%163 = add nsw i32 %162, -1
store i32 %163, i32* %12
%164 = icmp ne i32 %162, 0
br i1 %164, label %165, label %179
165: ; preds = %161
%166 = load i32, i32* %8
%167 = load i8*, i8** %14
%168 = load i32, i32* %11
%169 = call i32 @read(i32 %166, i8* %167, i32 %168)
%170 = load i8*, i8** %14
%171 = load i8*, i8** %15
%172 = load i32, i32* %11
%173 = call i32 @unsquash(i8* %170, i8* %171, i32 %172)
%174 = load i32, i32* %9
%175 = load i8*, i8** %15
%176 = load i32, i32* %11
%177 = mul nsw i32 %176, 2
%178 = call i32 @write(i32 %174, i8* %175, i32 %177)
br label %161
179: ; preds = %161
%180 = load i8*, i8** %14
%181 = call i32 @free(i8* %180)
%182 = load i8*, i8** %15
%183 = call i32 @free(i8* %182)
%184 = load i32, i32* %8
%185 = call i32 @close(i32 %184)
%186 = load i32, i32* %9
%187 = call i32 @close(i32 %186)
store i32 0, i32* %3
br label %188
188: ; preds = %179, %115, %94, %82, %74, %49, %37, %20
%189 = load i32, i32* %3
ret i32 %189
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [22 x i8] c"could not open infile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [23 x i8] c"could not open outfile\00"
@SEEK_CUR = global i32 0
@.str.2 = [22 x i8] c"invalid linelength %d\00"
@.str.3 = [14 x i8] c"out of memory\00"
@.str.4 = [26 x i8] c"linesize bigger than file\00"
@.str.5 = [60 x i8] c"Warning: file does not fit to linelength, %ld excess bytes\0A\00"
@.str.6 = [26 x i8] c"unsquashing %d lines now\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca %struct.stat
%5 = alloca [6 x i8]
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%8 = icmp eq i32 %0, 3
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @usage(i8* %10)
br label %104
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %104
22: ; preds = %12
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @O_TRUNC
%27 = or i32 %25, %26
%28 = tail call i32 (i8*, i32, ...) @open(i8* %16, i32 %27, i32 420)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @close(i32 %18)
br label %104
33: ; preds = %22
%34 = call i32 @read(i32 %18, i8* %3, i32 1)
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = shl nuw nsw i32 %36, 8
%38 = call i32 @read(i32 %18, i8* %3, i32 1)
%39 = load i8, i8* %3
%40 = zext i8 %39 to i32
%41 = or i32 %37, %40
%42 = load i32, i32* @SEEK_CUR
%43 = tail call i32 @lseek(i32 %18, i32 4, i32 %42)
%44 = icmp ugt i32 %41, 720
br i1 %44, label %45, label %47
45: ; preds = %33
%46 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %104
47: ; preds = %33
%48 = tail call i8* @malloc(i32 %41)
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%52 = tail call i32 @close(i32 %28)
%53 = tail call i32 @close(i32 %18)
br label %104
54: ; preds = %47
%55 = shl nuw nsw i32 %41, 1
%56 = tail call i8* @malloc(i32 %55)
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%60 = tail call i32 @free(i8* %48)
%61 = tail call i32 @close(i32 %28)
%62 = tail call i32 @close(i32 %18)
br label %104
63: ; preds = %54
%64 = call i32 @fstat(i32 %18, %struct.stat* %4)
%65 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%66 = load i32, i32* %65
%67 = add i32 %66, -6
%68 = sdiv i32 %67, %41
%69 = srem i32 %67, %41
%70 = icmp eq i32 %68, 0
br i1 %70, label %71, label %77
71: ; preds = %63
%72 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%73 = tail call i32 @free(i8* %48)
%74 = tail call i32 @free(i8* %56)
%75 = tail call i32 @close(i32 %28)
%76 = tail call i32 @close(i32 %18)
br label %104
77: ; preds = %63
%78 = icmp eq i32 %69, 0
br i1 %78, label %81, label %79
79: ; preds = %77
%80 = tail call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i32 %69)
br label %81
81: ; preds = %77, %79
%82 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %68)
store i8 %35, i8* %7
%83 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
store i8 %39, i8* %83
%84 = lshr i32 %68, 8
%85 = trunc i32 %84 to i8
%86 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 2
store i8 %85, i8* %86
%87 = trunc i32 %68 to i8
%88 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 3
store i8 %87, i8* %88
%89 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 4
store i8 0, i8* %89
%90 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
store i8 0, i8* %90
%91 = call i32 @write(i32 %28, i8* %7, i32 6)
br label %92
92: ; preds = %81, %92
%93 = phi i32 [ %94, %92 ], [ %68, %81 ]
%94 = add nsw i32 %93, -1
%95 = tail call i32 @read(i32 %18, i8* %48, i32 %41)
%96 = tail call i32 @unsquash(i8* %48, i8* %56, i32 %41)
%97 = tail call i32 @write(i32 %28, i8* %56, i32 %55)
%98 = icmp eq i32 %94, 0
br i1 %98, label %99, label %92
99: ; preds = %92
%100 = tail call i32 @free(i8* %48)
%101 = tail call i32 @free(i8* %56)
%102 = tail call i32 @close(i32 %18)
%103 = tail call i32 @close(i32 %28)
br label %104
104: ; preds = %99, %71, %58, %50, %45, %30, %20, %9
%105 = phi i32 [ 1, %9 ], [ 1, %20 ], [ 1, %30 ], [ 1, %45 ], [ 0, %99 ], [ 1, %71 ], [ 1, %58 ], [ 1, %50 ]
ret i32 %105
}