#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ close(int);
int dup2(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int read(int, char *, int);
char *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int get_window_size(int *longer, int *width) {
  int pipefd[2];
  int size;
  pid_t pid;
  char buffer[42];
  char *ptr;
  pipe(pipefd);
  if ((pid = fork()) == 0) {
    close(pipefd[0]);
    if (dup2(pipefd[1], 1) == -1)
      exit(1);
    system("stty size");
    close(pipefd[1]);
    exit(0);
  }
  size = read(pipefd[0], buffer, 42);
  if (size <= 0)
    return (1);
  buffer[size] = '\0';
  ptr = strstr(buffer, " ");
  *ptr = '\0';
  *width = atoi(buffer);
  *longer = atoi(ptr + 1);
  close(pipefd[1]);
  close(pipefd[0]);
  return (0);
}


x86 assembly (clang, -O0):
<get_window_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jne    11ff <get_window_size+0x6f>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11e4 <get_window_size+0x54>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe15(%rip),%rdi
call   1030 <system@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2a,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     1229 <get_window_size+0x99>
movl   $0x1,-0x4(%rbp)
jmp    128a <get_window_size+0xfa>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x60(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x68(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_window_size>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    0x8(%rsp),%edi
test   %eax,%eax
je     122d <get_window_size+0x9d>
lea    0x10(%rsp),%rsi
mov    $0x2a,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    121c <get_window_size+0x8c>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r15)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r14)
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    1221 <get_window_size+0x91>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
call   1060 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    124f <get_window_size+0xbf>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdaa(%rip),%rdi
call   1030 <system@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"stty size\00"
@.str.1 = [2 x i8] c" \00"
define i32 @get_window_size(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [42 x i8]
%10 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = call i32 (...) @fork()
store i32 %13, i32* %8
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @dup2(i32 %20, i32 1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %2
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds [42 x i8], [42 x i8]* %9, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 42)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp sle i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 1, i32* %3
br label %59
39: ; preds = %31
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [42 x i8], [42 x i8]* %9, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [42 x i8], [42 x i8]* %9, i64 0, i64 0
%44 = call i8* @strstr(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %44, i8** %10
%45 = load i8*, i8** %10
store i8 0, i8* %45
%46 = getelementptr inbounds [42 x i8], [42 x i8]* %9, i64 0, i64 0
%47 = call i32 @atoi(i8* %46)
%48 = load i32*, i32** %5
store i32 %47, i32* %48
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i32 @atoi(i8* %50)
%52 = load i32*, i32** %4
store i32 %51, i32* %52
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
store i32 0, i32* %3
br label %59
59: ; preds = %39, %38
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [10 x i8] c"stty size\00"
define i32 @get_window_size(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca [2 x i32]
%4 = alloca [42 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
%11 = load i32, i32* %7
br i1 %10, label %12, label %25
12: ; preds = %2
%13 = call i32 @close(i32 %11)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @dup2(i32 %15, i32 1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %14
%23 = call i32 @close(i32 %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = call i32 @read(i32 %11, i8* %6, i32 42)
%27 = icmp slt i32 %26, 1
br i1 %27, label %40, label %28
28: ; preds = %25
%29 = zext i32 %26 to i64
%30 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i8* @strchr(i8* %6, i32 32)
store i8 0, i8* %31
%32 = call i32 @atoi(i8* %6)
store i32 %32, i32* %1
%33 = getelementptr inbounds i8, i8* %31, i64 1
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %0
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %7
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %25, %28
%41 = phi i32 [ 0, %28 ], [ 1, %25 ]
ret i32 %41
}