#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int const);
void process_proc(int fd) {
  const int buffsize = 1024;
  char buffer[buffsize];
  ssize_t nbytes;
  for (;;) {
    nbytes = read(fd, buffer, buffsize - 1);
    if (nbytes <= 0)
      break;
    buffer[nbytes] = 0;
    printf("/proc/acpi/event: %s", buffer);
  }
}


x86 assembly (clang, -O0):
<process_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x400,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1040 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
ja     1164 <process_proc+0x44>
jmp    1188 <process_proc+0x68>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    0xe89(%rip),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <printf@plt>
jmp    113c <process_proc+0x1c>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_proc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x3ff,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1173 <process_proc+0x53>
lea    0xeba(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1040 <read@plt>
test   %rax,%rax
jne    1150 <process_proc+0x30>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/proc/acpi/event: %s\00"
define void @process_proc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %2
store i32 1024, i32* %3
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %4
%7 = alloca i8, i64 1024
br label %8
8: ; preds = %14, %1
%9 = load i32, i32* %2
%10 = call i64 @read(i32 %9, i8* %7, i32 1023)
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = icmp ule i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
br label %18
14: ; preds = %8
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %7, i64 %15
store i8 0, i8* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %8
18: ; preds = %13
%19 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/proc/acpi/event: %s\00"
define void @process_proc(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i64 @read(i32 %0, i8* %3, i32 1023)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %10, %6 ], [ %4, %1 ]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = call i64 @read(i32 %0, i8* %3, i32 1023)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %6, %1
ret void
}