#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*/ TIOCGWINSZ;
int atoi(char *);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  struct winsize w;
  ioctl(0, TIOCGWINSZ, &w);
  int COLS = (w.ws_col > 0 ? w.ws_col : 80);
  int lines = 1;
  if (argc > 1) {
    lines = atoi(argv[1]);
  }
  char outchar[COLS];
  for (int i = 0; i < COLS; i++) {
    outchar[i] = '#';
  }
  for (int x = 1; x <= lines; x++) {
    printf("%s\n", outchar);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmpl   $0x0,-0x18(%rbp)
jle    116f <main+0x3f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    117c <main+0x4c>
mov    $0x50,%eax
mov    %eax,-0x3c(%rbp)
jmp    117c <main+0x4c>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%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,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f6 <main+0xc6>
mov    -0x48(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x23,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d0 <main+0xa0>
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1227 <main+0xf7>
mov    -0x48(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11fd <main+0xcd>
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
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
xor    %edi,%edi
call   1050 <ioctl@plt>
mov    -0x30(%rbp),%eax
test   %eax,%eax
mov    $0x50,%r13d
cmovg  %eax,%r13d
mov    $0x1,%ebx
cmp    $0x2,%r15d
jl     118d <main+0x4d>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %rsp,%r12
mov    %r13d,%edx
mov    %rsp,%r14
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    $0x23,%esi
call   1040 <memset@plt>
test   %ebx,%ebx
jle    11d0 <main+0x90>
lea    0xe44(%rip),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0xffffffff,%ebx
jne    11c0 <main+0x80>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32 }
@TIOCGWINSZ = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %3 to i8*
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 0, i32 %5, %struct.winsize* %3)
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 80
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
br label %16
16: ; preds = %12, %2
%17 = phi i32 [ %15, %12 ], [ 1, %2 ]
%18 = zext i32 %10 to i64
%19 = call i8* @llvm.stacksave()
%20 = alloca i8, i64 %18
%21 = zext i32 %10 to i64
%22 = icmp slt i32 %17, 1
br i1 %22, label %23, label %24
23: ; preds = %24, %16
ret i32 0
24: ; preds = %16, %24
%25 = phi i32 [ %27, %24 ], [ 1, %16 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
%27 = add nuw i32 %25, 1
%28 = icmp eq i32 %25, %17
br i1 %28, label %23, label %24
}