#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 */
void *atoi(char *);
char *getenv(char *);
void get_term_dimensions(struct winsize *ws) {
  char *s = getenv("LINES");
  if (s != NULL) {
    ws->ws_row = atoi(s);
    s = getenv("COLUMNS");
    if (s != NULL) {
      ws->ws_col = atoi(s);
      if (ws->ws_row && ws->ws_col) {
        return;
      }
    }
  }
  ws->ws_row = 25;
  ws->ws_col = 80;
}


x86 assembly (clang, -O0):
<get_term_dimensions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11af <get_term_dimensions+0x8f>
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11aa <get_term_dimensions+0x8a>
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
je     11a5 <get_term_dimensions+0x85>
mov    -0x8(%rbp),%rax
cmpl   $0x0,0x4(%rax)
je     11a5 <get_term_dimensions+0x85>
jmp    11c4 <get_term_dimensions+0xa4>
jmp    11aa <get_term_dimensions+0x8a>
jmp    11af <get_term_dimensions+0x8f>
mov    -0x8(%rbp),%rax
movl   $0x19,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x50,0x4(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_term_dimensions>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116b <get_term_dimensions+0x4b>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %rax,%r14
mov    %r14d,(%rbx)
lea    0xeb9(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116b <get_term_dimensions+0x4b>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,0x4(%rbx)
test   %r14d,%r14d
je     116b <get_term_dimensions+0x4b>
test   %eax,%eax
jne    1178 <get_term_dimensions+0x58>
movabs $0x5000000019,%rax
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@.str = [6 x i8] c"LINES\00"
@.str.1 = [8 x i8] c"COLUMNS\00"
define void @get_term_dimensions(%struct.winsize* %0) {
%2 = alloca %struct.winsize*
%3 = alloca i8*
store %struct.winsize* %0, %struct.winsize** %2
%4 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %34
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i8* @atoi(i8* %8)
%10 = ptrtoint i8* %9 to i32
%11 = load %struct.winsize*, %struct.winsize** %2
%12 = getelementptr inbounds %struct.winsize, %struct.winsize* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %7
%17 = load i8*, i8** %3
%18 = call i8* @atoi(i8* %17)
%19 = ptrtoint i8* %18 to i32
%20 = load %struct.winsize*, %struct.winsize** %2
%21 = getelementptr inbounds %struct.winsize, %struct.winsize* %20, i32 0, i32 1
store i32 %19, i32* %21
%22 = load %struct.winsize*, %struct.winsize** %2
%23 = getelementptr inbounds %struct.winsize, %struct.winsize* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %16
%27 = load %struct.winsize*, %struct.winsize** %2
%28 = getelementptr inbounds %struct.winsize, %struct.winsize* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %39
32: ; preds = %26, %16
br label %33
33: ; preds = %32, %7
br label %34
34: ; preds = %33, %1
%35 = load %struct.winsize*, %struct.winsize** %2
%36 = getelementptr inbounds %struct.winsize, %struct.winsize* %35, i32 0, i32 0
store i32 25, i32* %36
%37 = load %struct.winsize*, %struct.winsize** %2
%38 = getelementptr inbounds %struct.winsize, %struct.winsize* %37, i32 0, i32 1
store i32 80, i32* %38
br label %39
39: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@.str = [6 x i8] c"LINES\00"
@.str.1 = [8 x i8] c"COLUMNS\00"
define void @get_term_dimensions(%struct.winsize* nocapture %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i8* @atoi(i8* %2)
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.winsize, %struct.winsize* %0, i64 0, i32 0
store i32 %7, i32* %8
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %4
%12 = tail call i8* @atoi(i8* %9)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds %struct.winsize, %struct.winsize* %0, i64 0, i32 1
store i32 %14, i32* %15
%16 = icmp eq i32 %7, 0
%17 = icmp eq i32 %14, 0
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %22
19: ; preds = %4, %11, %1
%20 = getelementptr inbounds %struct.winsize, %struct.winsize* %0, i64 0, i32 0
store i32 25, i32* %20
%21 = getelementptr inbounds %struct.winsize, %struct.winsize* %0, i64 0, i32 1
store i32 80, i32* %21
br label %22
22: ; preds = %11, %19
ret void
}