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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int strlen(char *);
const char *keymaps_header() {
  static char header[1024] = {'\0'};
  if (header[0] == '\0') {
    FILE *f = popen("dumpkeys | head -1", "r");
    if (f != NULL) {
      fgets(header, sizeof(header), f);
      pclose(f);
    }
    int length = strlen(header);
    if (length > 0 && header[length - 1] == '\n') {
      header[length - 1] = '\0';
    }
  }
  return header;
}


x86 assembly (clang, -O0):
<keymaps_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsbl 0x2f01(%rip),%eax
cmp    $0x0,%eax
jne    11e7 <keymaps_header+0xa7>
lea    0xea1(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1198 <keymaps_header+0x58>
mov    -0x8(%rbp),%rdx
lea    0x2ecb(%rip),%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1040 <pclose@plt>
lea    0x2eb1(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11e2 <keymaps_header+0xa2>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e8f(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11e2 <keymaps_header+0xa2>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e72(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    11e7 <keymaps_header+0xa7>
lea    0x2e62(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keymaps_header>:
push   %rbx
cmpb   $0x0,0x2f08(%rip)
je     1153 <keymaps_header+0x13>
lea    0x2eff(%rip),%rax
pop    %rbx
ret
lea    0xea6(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     118a <keymaps_header+0x4a>
mov    %rax,%rbx
lea    0x2edb(%rip),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0x2ebf(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    114a <keymaps_header+0xa>
add    $0xffffffff,%eax
cmpb   $0xa,(%rax,%rbx,1)
jne    114a <keymaps_header+0xa>
movb   $0x0,(%rax,%rbx,1)
jmp    114a <keymaps_header+0xa>

LLVM IR (-O0):
@keymaps_header.header = internal global [1024 x i8] zeroinitializer
@.str = [19 x i8] c"dumpkeys | head -1\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @keymaps_header() {
%1 = alloca i32*
%2 = alloca i32
%3 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0)
%4 = sext i8 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %33
6: ; preds = %0
%7 = call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %1
%8 = load i32*, i32** %1
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32*, i32** %1
%12 = call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0), i32 1024, i32* %11)
%13 = load i32*, i32** %1
%14 = call i32 @pclose(i32* %13)
br label %15
15: ; preds = %10, %6
%16 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0))
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %2
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %27, %19, %15
br label %33
33: ; preds = %32, %0
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0)
}

LLVM IR (-O2):
@keymaps_header.header = internal global [1024 x i8] zeroinitializer
@.str = [19 x i8] c"dumpkeys | head -1\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @keymaps_header() {
%1 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0)
%2 = icmp eq i8 %1, 0
br i1 %2, label %3, label %19
3: ; preds = %0
%4 = tail call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0), i32 1024, i32* %4)
%8 = tail call i32 @pclose(i32* %4)
br label %9
9: ; preds = %6, %3
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0))
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = add nsw i32 %10, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %12
store i8 0, i8* %15
br label %19
19: ; preds = %9, %12, %18, %0
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @keymaps_header.header, i64 0, i64 0)
}