#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*/ buildpacket(unsigned char *, int *, int, unsigned char *,
                               int);
int /*<<< orphan*/ convint(unsigned char *, int);
int listen(int, unsigned char *);
int /*<<< orphan*/ uncompressline(unsigned char *, unsigned char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int readline(int n, int fd, unsigned char *buf) {
  unsigned char pak[1024];
  unsigned char raw[1024];
  int len, res;
  unsigned char p[8];
  convint(&p[0], 1);
  convint(&p[2], n);
  convint(&p[4], 0);
  convint(&p[6], 250);
  buildpacket(pak, &len, 0x07, p, 8);
  write(fd, pak, len);
  res = listen(fd, raw);
  if (res > 1) {
    uncompressline(raw, buf);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x830(%rbp),%rdi
mov    $0x1,%esi
call   1070 <convint@plt>
lea    -0x830(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%esi
call   1070 <convint@plt>
lea    -0x830(%rbp),%rdi
add    $0x4,%rdi
xor    %esi,%esi
call   1070 <convint@plt>
lea    -0x830(%rbp),%rdi
add    $0x6,%rdi
mov    $0xfa,%esi
call   1070 <convint@plt>
lea    -0x420(%rbp),%rdi
lea    -0x830(%rbp),%rcx
lea    -0x824(%rbp),%rsi
mov    $0x7,%edx
mov    $0x8,%r8d
call   1050 <buildpacket@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x824(%rbp),%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
call   1060 <listen@plt>
mov    %eax,-0x828(%rbp)
cmpl   $0x1,-0x828(%rbp)
jle    1228 <readline+0xd8>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <uncompressline@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <readline+0xdf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
call   1070 <convint@plt>
lea    0xa(%rsp),%rdi
mov    %ebx,%esi
call   1070 <convint@plt>
lea    0xc(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
call   1070 <convint@plt>
lea    0xe(%rsp),%rdi
mov    $0xfa,%esi
call   1070 <convint@plt>
lea    0x410(%rsp),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
mov    %r15,%rcx
mov    $0x8,%r8d
call   1050 <buildpacket@plt>
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
call   1060 <listen@plt>
cmp    $0x2,%eax
jl     11f7 <readline+0xa7>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1040 <uncompressline@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readline(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [8 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%14 = call i32 @convint(i8* %13, i32 1)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 2
%16 = load i32, i32* %5
%17 = call i32 @convint(i8* %15, i32 %16)
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 4
%19 = call i32 @convint(i8* %18, i32 0)
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 6
%21 = call i32 @convint(i8* %20, i32 250)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%24 = call i32 @buildpacket(i8* %22, i32* %10, i32 7, i8* %23, i32 8)
%25 = load i32, i32* %6
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* %10
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %6
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%31 = call i32 @listen(i32 %29, i8* %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %3
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = load i8*, i8** %7
%37 = call i32 @uncompressline(i8* %35, i8* %36)
store i32 1, i32* %4
br label %39
38: ; preds = %3
store i32 0, i32* %4
br label %39
39: ; preds = %38, %34
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @readline(i32 %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca [8 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%12 = call i32 @convint(i8* %11, i32 1)
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 2
%14 = call i32 @convint(i8* %13, i32 %0)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 4
%16 = call i32 @convint(i8* %15, i32 0)
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 6
%18 = call i32 @convint(i8* %17, i32 250)
%19 = call i32 @buildpacket(i8* %8, i32* %6, i32 7, i8* %11, i32 8)
%20 = load i32, i32* %6
%21 = call i32 @write(i32 %1, i8* %8, i32 %20)
%22 = call i32 @listen(i32 %1, i8* %9)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %3
%25 = call i32 @uncompressline(i8* %9, i8* %2)
br label %26
26: ; preds = %3, %24
%27 = phi i32 [ 1, %24 ], [ 0, %3 ]
ret i32 %27
}