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

/* Variables and functions */
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void write_full_row(void) {
  struct winsize w;
  ioctl(1, TIOCGWINSZ, &w);
  printf("Term size: %d rows x %d cols\n\n", w.ws_row, w.ws_col);
  printf("TEST 1) Full row with '-':\n");
  for (int i = 0; i < w.ws_col; i++)
    putchar('-');
  printf("[text after full row]\n\n\n");
  printf("TEST 2) Now full row with '-' + \\n\n");
  for (int i = 0; i < w.ws_col; i++)
    putchar('-');
  putchar('\n');
  printf("[text after full row]\n\n");
}


x86 assembly (clang, -O0):
<write_full_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x8(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119c <write_full_row+0x6c>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <write_full_row+0x48>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e3 <write_full_row+0xb3>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bf <write_full_row+0x8f>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_full_row>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
call   1060 <ioctl@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe94(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11a3 <write_full_row+0x63>
nopl   0x0(%rax,%rax,1)
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     1190 <write_full_row+0x50>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11e3 <write_full_row+0xa3>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     11d0 <write_full_row+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
@.str = [31 x i8] c"Term size: %d rows x %d cols\0A\0A\00"
@.str.1 = [28 x i8] c"TEST 1) Full row with '-':\0A\00"
@.str.2 = [25 x i8] c"[text after full row]\0A\0A\0A\00"
@.str.3 = [36 x i8] c"TEST 2) Now full row with '-' + \\n\0A\00"
@.str.4 = [24 x i8] c"[text after full row]\0A\0A\00"
define void @write_full_row() {
%1 = alloca %struct.winsize
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @TIOCGWINSZ
%5 = call i32 @ioctl(i32 1, i32 %4, %struct.winsize* %1)
%6 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i32 0, i32 1
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %12
12: ; preds = %19, %0
%13 = load i32, i32* %2
%14 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i32 0, i32 1
%15 = load i32, i32* %14
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = call i32 @putchar(i8 signext 45)
br label %19
19: ; preds = %17
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %12
22: ; preds = %12
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %25
25: ; preds = %32, %22
%26 = load i32, i32* %3
%27 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i32 0, i32 1
%28 = load i32, i32* %27
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = call i32 @putchar(i8 signext 45)
br label %32
32: ; preds = %30
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %25
35: ; preds = %25
%36 = call i32 @putchar(i8 signext 10)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
@.str = [31 x i8] c"Term size: %d rows x %d cols\0A\0A\00"
@str = [27 x i8] c"TEST 1) Full row with '-':\00"
@str.5 = [24 x i8] c"[text after full row]\0A\0A\00"
@str.6 = [35 x i8] c"TEST 2) Now full row with '-' + \\n\00"
@str.7 = [23 x i8] c"[text after full row]\0A\00"
define void @write_full_row() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = load i32, i32* @TIOCGWINSZ
%4 = call i32 @ioctl(i32 1, i32 %3, %struct.winsize* %1)
%5 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 1
%8 = load i32, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %18, %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %27, label %24
18: ; preds = %0, %18
%19 = phi i32 [ %21, %18 ], [ 0, %0 ]
%20 = call i32 @putchar(i8 signext 45)
%21 = add nuw nsw i32 %19, 1
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %18, label %13
24: ; preds = %27, %13
%25 = call i32 @putchar(i8 signext 10)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
ret void
27: ; preds = %13, %27
%28 = phi i32 [ %30, %27 ], [ 0, %13 ]
%29 = call i32 @putchar(i8 signext 45)
%30 = add nuw nsw i32 %28, 1
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %27, label %24
}