#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int syscall(int /*<<< orphan*/, int, char *, int);
int main(void) {
  int read_chars = 0;
  int fd = 0;
  char buf[512 + 1];
  fd = open("/proc/cpuinfo", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Can't open the file\n");
    exit(1);
  }
  while ((read_chars = syscall(0, fd, buf, 512)) > 0) {
    buf[read_chars] = '\0';
    printf("%s", buf);
  }
  if (read_chars < 0) {
    fprintf(stderr, "Error while reading the file\n");
    exit(1);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c1 <main+0x61>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c6 <main+0x66>
mov    -0xc(%rbp),%esi
lea    -0x210(%rbp),%rdx
xor    %edi,%edi
mov    $0x200,%ecx
call   1060 <syscall@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    120c <main+0xac>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
jmp    11c6 <main+0x66>
cmpl   $0x0,-0x8(%rbp)
jge    1235 <main+0xd5>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11ef <main+0x8f>
mov    %eax,%ebp
mov    %rsp,%rdx
xor    %edi,%edi
mov    %eax,%esi
mov    $0x200,%ecx
call   1060 <syscall@plt>
test   %eax,%eax
jle    11d6 <main+0x76>
lea    0xe81(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    $0x200,%ecx
call   1060 <syscall@plt>
test   %eax,%eax
jg     11b0 <main+0x50>
test   %eax,%eax
js     1201 <main+0xa1>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
jmp    1211 <main+0xb1>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open the file\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [30 x i8] c"Error while reading the file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [513 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = load i32, i32* %3
%16 = getelementptr inbounds [513 x i8], [513 x i8]* %4, i64 0, i64 0
%17 = call i32 @syscall(i32 0, i32 %15, i8* %16, i32 512)
store i32 %17, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [513 x i8], [513 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %4, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %14
25: ; preds = %14
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open the file\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [30 x i8] c"Error while reading the file\0A\00"
define i32 @main() {
%1 = alloca [513 x i8]
%2 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @syscall(i32 0, i32 %4, i8* %2, i32 512)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %13, label %20
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %13
%14 = phi i32 [ %18, %13 ], [ %7, %6 ]
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [513 x i8], [513 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%18 = call i32 @syscall(i32 0, i32 %4, i8* %2, i32 512)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %13, label %20
20: ; preds = %13, %6
%21 = phi i32 [ %7, %6 ], [ %18, %13 ]
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = call i32 @close(i32 %4)
ret i32 0
}