#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 open(char *, int /*<<< orphan*/);
int read(int, char **, int);
int /*<<< orphan*/ write(int, char **, int);
void *print_thread_info() {
  int fd;
  fd = open("/proc/self/status", O_RDONLY);
  char *buf[1024];
  int n;
  while (n = read(fd, buf, 1024)) {
    write(1, buf, n);
  }
}


x86 assembly (clang, -O0):
<print_thread_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x2010(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x2014(%rbp)
cmp    $0x0,%eax
je     1192 <print_thread_info+0x62>
lea    -0x2010(%rbp),%rsi
mov    -0x2014(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1153 <print_thread_info+0x23>
mov    -0x8(%rbp),%rax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_thread_info>:
push   %rbp
push   %rbx
sub    $0x2008,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
je     1192 <print_thread_info+0x62>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jne    1170 <print_thread_info+0x40>
add    $0x2008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@O_RDONLY = global i32 0
define i8* @print_thread_info() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [1024 x i8*]
%4 = alloca i32
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
br label %7
7: ; preds = %12, %0
%8 = load i32, i32* %2
%9 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8** %9, i32 1024)
store i32 %10, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @write(i32 1, i8** %13, i32 %14)
br label %7
16: ; preds = %7
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@O_RDONLY = global i32 0
define noalias i8* @print_thread_info() {
%1 = alloca [1024 x i8*]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = bitcast [1024 x i8*]* %1 to i8*
%5 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %1, i64 0, i64 0
%6 = call i32 @read(i32 %3, i8** %5, i32 1024)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ %6, %0 ]
%10 = call i32 @write(i32 1, i8** %5, i32 %9)
%11 = call i32 @read(i32 %3, i8** %5, i32 1024)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8, %0
ret i8* undef
}