#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int read_pcx_line(FILE *f, unsigned char *buf, int len) {
  unsigned char *ptr;
  int cnt;
  int c;
  for (ptr = buf; ptr < buf + len;) {
    if ((c = getc(f)) == EOF) {
      return 0;
    }
    if ((c & 0xC0) != 0xC0)
      *ptr++ = c;
    else {
      cnt = c & 0x3F;
      if ((c = getc(f)) == EOF) {
        return 0;
      }
      memset(ptr, c, cnt);
      ptr += cnt;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_pcx_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11fd <read_pcx_line+0xdd>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%eax
jne    117a <read_pcx_line+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1204 <read_pcx_line+0xe4>
mov    -0x30(%rbp),%eax
and    $0xc0,%eax
cmp    $0xc0,%eax
je     11a8 <read_pcx_line+0x88>
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    11f8 <read_pcx_line+0xd8>
mov    -0x30(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11d8 <read_pcx_line+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    1204 <read_pcx_line+0xe4>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <memset@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    113b <read_pcx_line+0x1b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pcx_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1199 <read_pcx_line+0x79>
mov    %rsi,%r15
mov    %rdi,%r14
movslq %edx,%r12
add    %rsi,%r12
mov    0x2ea6(%rip),%r13
xor    %ebx,%ebx
jmp    115c <read_pcx_line+0x3c>
cs nopw 0x0(%rax,%rax,1)
mov    %bpl,(%r15)
add    $0x1,%r15
cmp    %r12,%r15
jae    1199 <read_pcx_line+0x79>
mov    %r14,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
je     119e <read_pcx_line+0x7e>
mov    %eax,%ebp
not    %eax
test   $0xc0,%al
jne    1150 <read_pcx_line+0x30>
mov    %r14,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
je     119e <read_pcx_line+0x7e>
and    $0x3f,%ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    %ebp,%eax
add    %rax,%r15
cmp    %r12,%r15
jb     115c <read_pcx_line+0x3c>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @read_pcx_line(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
store i8* %11, i8** %8
br label %12
12: ; preds = %51, %3
%13 = load i8*, i8** %8
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = icmp ult i8* %13, %17
br i1 %18, label %19, label %52
19: ; preds = %12
%20 = load i32*, i32** %5
%21 = call i32 @getc(i32* %20)
store i32 %21, i32* %10
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %4
br label %53
25: ; preds = %19
%26 = load i32, i32* %10
%27 = and i32 %26, 192
%28 = icmp ne i32 %27, 192
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* %10
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %8
store i8 %31, i8* %32
br label %51
34: ; preds = %25
%35 = load i32, i32* %10
%36 = and i32 %35, 63
store i32 %36, i32* %9
%37 = load i32*, i32** %5
%38 = call i32 @getc(i32* %37)
store i32 %38, i32* %10
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 0, i32* %4
br label %53
42: ; preds = %34
%43 = load i8*, i8** %8
%44 = load i32, i32* %10
%45 = load i32, i32* %9
%46 = call i32 @memset(i8* %43, i32 %44, i32 %45)
%47 = load i32, i32* %9
%48 = load i8*, i8** %8
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %8
br label %51
51: ; preds = %42, %29
br label %12
52: ; preds = %12
store i32 1, i32* %4
br label %53
53: ; preds = %52, %41, %24
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_pcx_line(i32* nocapture %0, i8* %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %30
7: ; preds = %3, %27
%8 = phi i8* [ %28, %27 ], [ %1, %3 ]
%9 = tail call i32 @getc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %30, label %12
12: ; preds = %7
%13 = and i32 %9, 192
%14 = icmp eq i32 %13, 192
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = trunc i32 %9 to i8
%17 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %16, i8* %8
br label %27
18: ; preds = %12
%19 = and i32 %9, 63
%20 = tail call i32 @getc(i32* %0)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = tail call i32 @memset(i8* %8, i32 %20, i32 %19)
%25 = zext i32 %19 to i64
%26 = getelementptr inbounds i8, i8* %8, i64 %25
br label %27
27: ; preds = %23, %15
%28 = phi i8* [ %17, %15 ], [ %26, %23 ]
%29 = icmp ult i8* %28, %5
br i1 %29, label %7, label %30
30: ; preds = %7, %18, %27, %3
%31 = phi i32 [ 1, %3 ], [ 1, %27 ], [ 0, %18 ], [ 0, %7 ]
ret i32 %31
}