#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ setupterm(int /*<<< orphan*/ *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ stdout;
int tigetnum(char *);
int main() {
  int nrows, ncolumns;
  setupterm(NULL, fileno(stdout), (int *)0);
  nrows = tigetnum("lines");
  ncolumns = tigetnum("cols");
  printf("This terminal has %d columns and %d rows\n", ncolumns, nrows);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rdi
call   1030 <setupterm@plt>
lea    0xe7e(%rip),%rdi
call   1070 <tigetnum@plt>
mov    %eax,-0x8(%rbp)
lea    0xe75(%rip),%rdi
call   1070 <tigetnum@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
xor    %edi,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1030 <setupterm@plt>
lea    0xe8f(%rip),%rdi
call   1070 <tigetnum@plt>
mov    %eax,%ebx
lea    0xe87(%rip),%rdi
call   1070 <tigetnum@plt>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [6 x i8] c"lines\00"
@.str.1 = [5 x i8] c"cols\00"
@.str.2 = [42 x i8] c"This terminal has %d columns and %d rows\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stdout
%5 = call i32 @fileno(i32 %4)
%6 = call i32 @setupterm(i32* null, i32 %5, i32* null)
%7 = call i32 @tigetnum(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %2
%8 = call i32 @tigetnum(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [6 x i8] c"lines\00"
@.str.1 = [5 x i8] c"cols\00"
@.str.2 = [42 x i8] c"This terminal has %d columns and %d rows\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @fileno(i32 %1)
%3 = tail call i32 @setupterm(i32* null, i32 %2, i32* null)
%4 = tail call i32 @tigetnum(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @tigetnum(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %4)
%7 = tail call i32 @exit(i32 0)
unreachable
}