#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*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
void read_irc(char buffer[], int sockfd) {
  int n;
  do {
    bzero(buffer, 1024);
    n = read(sockfd, buffer, 1024 - 1);
    if (n < 0)
      error("ERROR reading from socket");
    if (n > 0)
      printf("%s", buffer);
  } while (n == 1024);
}


x86 assembly (clang, -O0):
<read_irc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x400,%esi
call   1060 <bzero@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x3ff,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1187 <read_irc+0x47>
lea    0xe7e(%rip),%rdi
call   1050 <error@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11a1 <read_irc+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
jmp    11a6 <read_irc+0x66>
cmpl   $0x400,-0x10(%rbp)
je     114f <read_irc+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_irc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xec6(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x400,%esi
call   1060 <bzero@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11a3 <read_irc+0x63>
je     1198 <read_irc+0x58>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
cmp    $0x400,%ebp
je     1160 <read_irc+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe56(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <error@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [3 x i8] c"%s\00"
define void @read_irc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %23, %2
%7 = load i8*, i8** %3
%8 = call i32 @bzero(i8* %7, i32 1024)
%9 = load i32, i32* %4
%10 = load i8*, i8** %3
%11 = call i32 @read(i32 %9, i8* %10, i32 1023)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %6
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %22
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 1024
br i1 %25, label %6, label %26
26: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [3 x i8] c"%s\00"
define void @read_irc(i8* %0, i32 %1) {
br label %3
3: ; preds = %11, %2
%4 = tail call i32 @bzero(i8* %0, i32 1024)
%5 = tail call i32 @read(i32 %1, i8* %0, i32 1023)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
9: ; preds = %3
%10 = icmp eq i32 %5, 0
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = icmp eq i32 %5, 1024
br i1 %13, label %3, label %14
14: ; preds = %9, %11, %7
ret void
}