#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);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
void print_sys_reg_info() {
  char *buf;
  int rd_size;
  int fd = open("/proc/sys_reg", O_RDONLY);
  if (fd < 0) {
    printf("open failed\n");
    return;
  }
  buf = (char *)malloc(4096);
  if (buf == NULL) {
    printf("malloc failed\n");
    return;
  }
  rd_size = read(fd, buf, 4096 - 1);
  if (rd_size < 0) {
    printf("read failed\n");
    return;
  }
  buf[rd_size] = 0;
  printf("%s", buf);
  close(fd);
}


x86 assembly (clang, -O0):
<print_sys_reg_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    118d <print_sys_reg_info+0x3d>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <print_sys_reg_info+0xc0>
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b9 <print_sys_reg_info+0x69>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <print_sys_reg_info+0xc0>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0xfff,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ea <print_sys_reg_info+0x9a>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <print_sys_reg_info+0xc0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sys_reg_info>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11c7 <print_sys_reg_info+0x67>
mov    %eax,%ebp
mov    $0x1000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d0 <print_sys_reg_info+0x70>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0xfff,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11d9 <print_sys_reg_info+0x79>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>
lea    0xe5d(%rip),%rdi
jmp    11e0 <print_sys_reg_info+0x80>
lea    0xe46(%rip),%rdi
jmp    11e0 <print_sys_reg_info+0x80>
lea    0xe31(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/sys_reg\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open failed\0A\00"
@.str.2 = [15 x i8] c"malloc failed\0A\00"
@.str.3 = [13 x i8] c"read failed\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @print_sys_reg_info() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %34
10: ; preds = %0
%11 = call i64 @malloc(i32 4096)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %1
%13 = load i8*, i8** %1
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %34
17: ; preds = %10
%18 = load i32, i32* %3
%19 = load i8*, i8** %1
%20 = call i32 @read(i32 %18, i8* %19, i32 4095)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %34
25: ; preds = %17
%26 = load i8*, i8** %1
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %3
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %25, %23, %15, %8
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/sys_reg\00"
@O_RDONLY = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@str = [12 x i8] c"read failed\00"
@str.5 = [14 x i8] c"malloc failed\00"
@str.6 = [12 x i8] c"open failed\00"
define void @print_sys_reg_info() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %22
6: ; preds = %0
%7 = tail call i64 @malloc(i32 4096)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %22
12: ; preds = %6
%13 = tail call i32 @read(i32 %2, i8* %8, i32 4095)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %22
17: ; preds = %12
%18 = zext i32 %13 to i64
%19 = getelementptr inbounds i8, i8* %8, i64 %18
store i8 0, i8* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%21 = tail call i32 @close(i32 %2)
br label %22
22: ; preds = %17, %15, %10, %4
ret void
}