#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fatal(char *);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int number_of_columns() {
  int fda;
  unsigned char rc[2];
  if ((fda = open("/dev/vcsa", O_RDONLY)) < 0 &&
      (fda = open("/dev/vcsa0", O_RDONLY)) < 0)
    fatal("/dev/vcsa");
  if (read(fda, rc, 2) != 2)
    fatal("/dev/vcsa");
  close(fda);
  return rc[1];
}


x86 assembly (clang, -O0):
<number_of_columns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1196 <number_of_columns+0x56>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1196 <number_of_columns+0x56>
lea    0xe6f(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     11bc <number_of_columns+0x7c>
lea    0xe49(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
movzbl -0x5(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_of_columns>:
push   %r14
push   %rbx
push   %rax
mov    0x2e9d(%rip),%r14
mov    (%r14),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1181 <number_of_columns+0x41>
mov    (%r14),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1181 <number_of_columns+0x41>
lea    0xe84(%rip),%rdi
call   1060 <fatal@plt>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     11a3 <number_of_columns+0x63>
lea    0xe62(%rip),%rdi
call   1060 <fatal@plt>
mov    %ebx,%edi
call   1030 <close@plt>
movzbl 0x7(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/vcsa\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/vcsa0\00"
define i32 @number_of_columns() {
%1 = alloca i32
%2 = alloca [2 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 %8, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6, %0
%13 = load i32, i32* %1
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 2)
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* %1
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
ret i32 %24
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/vcsa\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/vcsa0\00"
define i32 @number_of_columns() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6, %0
%13 = phi i32 [ %8, %10 ], [ %8, %6 ], [ %4, %0 ]
%14 = call i32 @read(i32 %13, i8* %2, i32 2)
%15 = icmp eq i32 %14, 2
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = tail call i32 @close(i32 %13)
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
ret i32 %22
}