#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;
  int ws_row;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int main(int argc, char **argv) {
  struct winsize x = {0};
  ioctl(STDOUT_FILENO, TIOCGWINSZ, &x);
  FILE *f = fopen(argv[1], "w");
  fprintf(f,
          "#ifndef _TERMINAL_TERMINAL_H_\n"
          "#define _TERMINAL_TERMINAL_H_\n"
          "\n"
          "/* THIS FILE IS AUTOGENERATED. DO NOT EDIT. */\n"
          "\n"
          "#define TERMINAL_WIDTH %d\n"
          "#define TERMINAL_HEIGHT %d\n"
          "\n"
          "#endif /* !_TERMINAL_TERMINAL_H_ */\n",
          x.ws_col, x.ws_row);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <ioctl@plt>
mov    0x8(%rbx),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe6f(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [200 x i8] c"#ifndef _TERMINAL_TERMINAL_H_\0A#define _TERMINAL_TERMINAL_H_\0A\0A/* THIS FILE IS AUTOGENERATED. DO NOT EDIT. */\0A\0A#define TERMINAL_WIDTH %d\0A#define TERMINAL_HEIGHT %d\0A\0A#endif /* !_TERMINAL_TERMINAL_H_ */\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast %struct.winsize* %6 to i8*
%9 = load i32, i32* @STDOUT_FILENO
%10 = load i32, i32* @TIOCGWINSZ
%11 = call i32 @ioctl(i32 %9, i32 %10, %struct.winsize* %6)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %20)
%22 = load i32*, i32** %7
%23 = call i32 @fclose(i32* %22)
ret i32 0
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [200 x i8] c"#ifndef _TERMINAL_TERMINAL_H_\0A#define _TERMINAL_TERMINAL_H_\0A\0A/* THIS FILE IS AUTOGENERATED. DO NOT EDIT. */\0A\0A#define TERMINAL_WIDTH %d\0A#define TERMINAL_HEIGHT %d\0A\0A#endif /* !_TERMINAL_TERMINAL_H_ */\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* @STDOUT_FILENO
%6 = load i32, i32* @TIOCGWINSZ
%7 = call i32 @ioctl(i32 %5, i32 %6, %struct.winsize* %3)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
%16 = call i32 @fclose(i32* %10)
ret i32 0
}