#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 winsize {
  int ws_col;
};

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int errno;
int execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(void) {
  struct winsize w;
  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
    w.ws_col = 130;
  }
  for (int c = 10; c < w.ws_col; c += 10) {
    printf("%10d", c / 10);
  }
  printf("\n");
  for (int c = 1; c < w.ws_col; ++c) {
    printf("%c", c % 10 == 0 ? '0' : c % 5 == 0 ? '+' : '.');
  }
  printf("\n");
  fflush(stdout);
  if (execl("/bin/cat", "/bin/cat", "-", NULL) == -1) {
    printf("err = %d when starting cat\n", errno);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    117a <main+0x3a>
movl   $0x82,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b6 <main+0x76>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
jmp    1181 <main+0x41>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1235 <main+0xf5>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11f8 <main+0xb8>
mov    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    1216 <main+0xd6>
mov    -0x10(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    $0x2e,%eax
mov    $0x2b,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cb <main+0x8b>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xdb0(%rip),%rsi
lea    0xdb2(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1060 <execl@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0x14b>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1182 <main+0x32>
cmpl   $0xb,0x8(%rsp)
jge    118a <main+0x3a>
jmp    11b8 <main+0x68>
movl   $0x82,0x8(%rsp)
mov    $0xa,%ebp
mov    $0x1,%ebx
lea    0xe65(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xa,%ebp
add    $0x1,%ebx
cmp    0x8(%rsp),%ebp
jl     11a0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x2,0x8(%rsp)
jl     1229 <main+0xd9>
mov    $0x1,%ebx
mov    $0xcccccccd,%r14d
jmp    11ee <main+0x9e>
cs nopw 0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jge    1229 <main+0xd9>
mov    %ebx,%eax
imul   %r14,%rax
mov    %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    $0x30,%edi
cmp    %ecx,%ebx
je     11e0 <main+0x90>
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
mov    $0x1,%ecx
sub    %eax,%ecx
add    %ebx,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
lea    (%rax,%rax,2),%edi
add    $0x2b,%edi
jmp    11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xdbd(%rip),%rdi
lea    0xdbf(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1070 <execl@plt>
cmp    $0xffffffff,%eax
jne    1275 <main+0x125>
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xda2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.winsize = type { i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [5 x i8] c"%10d\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%c\00"
@stdout = global i32 0
@.str.3 = [9 x i8] c"/bin/cat\00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [28 x i8] c"err = %d when starting cat\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.winsize
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @STDOUT_FILENO
%6 = load i32, i32* @TIOCGWINSZ
%7 = call i32 @ioctl(i32 %5, i32 %6, %struct.winsize* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
store i32 130, i32* %10
br label %11
11: ; preds = %9, %0
store i32 10, i32* %3
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %3
%14 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 10
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 10
store i32 %23, i32* %3
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %26
26: ; preds = %45, %24
%27 = load i32, i32* %4
%28 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%29 = load i32, i32* %28
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %48
31: ; preds = %26
%32 = load i32, i32* %4
%33 = srem i32 %32, 10
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %42
36: ; preds = %31
%37 = load i32, i32* %4
%38 = srem i32 %37, 5
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 43, i32 46
br label %42
42: ; preds = %36, %35
%43 = phi i32 [ 48, %35 ], [ %41, %36 ]
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %26
48: ; preds = %26
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* @stdout
%51 = call i32 @fflush(i32 %50)
%52 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* null)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* @errno
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %48
ret i32 0
}

LLVM IR (-O2):
%struct.winsize = type { i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [5 x i8] c"%10d\00"
@stdout = global i32 0
@.str.3 = [9 x i8] c"/bin/cat\00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [28 x i8] c"err = %d when starting cat\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = load i32, i32* @STDOUT_FILENO
%4 = load i32, i32* @TIOCGWINSZ
%5 = call i32 @ioctl(i32 %3, i32 %4, %struct.winsize* %1)
%6 = icmp eq i32 %5, -1
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
br i1 %6, label %8, label %9
8: ; preds = %0
store i32 130, i32* %7
br label %12
9: ; preds = %0
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %8, %9
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
br label %19
14: ; preds = %19, %9
%15 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%16 = call i32 @putchar(i32 10)
%17 = load i32, i32* %15
%18 = icmp sgt i32 %17, 1
br i1 %18, label %32, label %26
19: ; preds = %12, %19
%20 = phi i32 [ %23, %19 ], [ 10, %12 ]
%21 = udiv i32 %20, 10
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i32 %20, 10
%24 = load i32, i32* %13
%25 = icmp slt i32 %23, %24
br i1 %25, label %19, label %14
26: ; preds = %40, %14
%27 = call i32 @putchar(i32 10)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
%30 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* null)
%31 = icmp eq i32 %30, -1
br i1 %31, label %46, label %49
32: ; preds = %14, %40
%33 = phi i32 [ %43, %40 ], [ 1, %14 ]
%34 = urem i32 %33, 10
%35 = icmp eq i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = urem i32 %33, 5
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i32 43, i32 46
br label %40
40: ; preds = %32, %36
%41 = phi i32 [ %39, %36 ], [ 48, %32 ]
%42 = call i32 @putchar(i32 %41)
%43 = add nuw nsw i32 %33, 1
%44 = load i32, i32* %15
%45 = icmp slt i32 %43, %44
br i1 %45, label %32, label %26
46: ; preds = %26
%47 = load i32, i32* @errno
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %26
ret i32 0
}