#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int mustreadword(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int convertcolor(FILE *fp, int ver, int *r, int *g, int *b, char *name,
                 int buflen) {
  int cspace = mustreadword(fp);
  int namelen;
  if (cspace != 0) {
    int j;
    for (j = 0; j < 4; j++)
      mustreadword(fp);
    if (ver == 2) {
      mustreadword(fp);
      namelen = mustreadword(fp);
      for (j = 0; j < namelen; j++)
        mustreadword(fp);
    }
    fprintf(stderr, "Non RGB color (colorspace %d) skipped\n", cspace);
    return 1;
  }
  *r = mustreadword(fp) / 256;
  *g = mustreadword(fp) / 256;
  *b = mustreadword(fp) / 256;
  mustreadword(fp);
  if (ver == 1)
    return 0;
  mustreadword(fp);
  namelen = mustreadword(fp);
  namelen--;
  while (namelen > 0) {
    int c = mustreadword(fp);
    if (c > 0xff)
      c = ' ';
    if (buflen > 1) {
      *name++ = c;
      buflen--;
    }
    namelen--;
  }
  *name = '\0';
  mustreadword(fp);
  return 0;
}


x86 assembly (clang, -O0):
<convertcolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11f2 <convertcolor+0xd2>
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1180 <convertcolor+0x60>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    115f <convertcolor+0x3f>
cmpl   $0x2,-0x14(%rbp)
jne    11ce <convertcolor+0xae>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    11c9 <convertcolor+0xa9>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a6 <convertcolor+0x86>
jmp    11ce <convertcolor+0xae>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xe1f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <convertcolor+0x1d2>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
cmpl   $0x1,-0x14(%rbp)
jne    125c <convertcolor+0x13c>
movl   $0x0,-0x4(%rbp)
jmp    12f2 <convertcolor+0x1d2>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jle    12db <convertcolor+0x1bb>
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xff,-0x48(%rbp)
jle    12a4 <convertcolor+0x184>
movl   $0x20,-0x48(%rbp)
cmpl   $0x1,0x10(%rbp)
jle    12cd <convertcolor+0x1ad>
mov    -0x48(%rbp),%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,0x10(%rbp)
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
jmp    127a <convertcolor+0x15a>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <mustreadword@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertcolor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,(%rsp)
mov    %rcx,%r13
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <mustreadword@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
test   %r12d,%r12d
je     11c0 <convertcolor+0xa0>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
cmp    $0x2,%ebp
jne    119d <convertcolor+0x7d>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
test   %eax,%eax
jle    119d <convertcolor+0x7d>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
add    $0xffffffff,%ebp
jne    1190 <convertcolor+0x70>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    %r12d,%edx
call   1030 <fprintf@plt>
mov    $0x1,%r15d
jmp    1278 <convertcolor+0x158>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x8,%ecx
mov    %ecx,(%r15)
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x8,%ecx
mov    %ecx,0x0(%r13)
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x8,%ecx
mov    (%rsp),%rax
mov    %ecx,(%rax)
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
xor    %r15d,%r15d
cmp    $0x1,%ebp
je     1278 <convertcolor+0x158>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
cmp    $0x2,%eax
jl     126c <convertcolor+0x14c>
mov    %eax,%ebp
mov    0x40(%rsp),%r12d
add    $0x1,%ebp
mov    $0x20,%r13d
jmp    1248 <convertcolor+0x128>
xchg   %ax,%ax
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jbe    126c <convertcolor+0x14c>
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
cmp    $0x2,%r12d
jl     1240 <convertcolor+0x120>
cmp    $0x100,%eax
cmovge %r13d,%eax
mov    %al,(%r14)
add    $0x1,%r14
add    $0xffffffff,%r12d
jmp    1240 <convertcolor+0x120>
movb   $0x0,(%r14)
mov    %rbx,%rdi
call   1040 <mustreadword@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Non RGB color (colorspace %d) skipped\0A\00"
define i32 @convertcolor(i32* %0, i32 %1, i32* %2, i32* %3, i32* %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %9
store i32 %1, i32* %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i8* %5, i8** %14
store i32 %6, i32* %15
%20 = load i32*, i32** %9
%21 = call i32 @mustreadword(i32* %20)
store i32 %21, i32* %16
%22 = load i32, i32* %16
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %57
24: ; preds = %7
store i32 0, i32* %18
br label %25
25: ; preds = %31, %24
%26 = load i32, i32* %18
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32*, i32** %9
%30 = call i32 @mustreadword(i32* %29)
br label %31
31: ; preds = %28
%32 = load i32, i32* %18
%33 = add nsw i32 %32, 1
store i32 %33, i32* %18
br label %25
34: ; preds = %25
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %53
37: ; preds = %34
%38 = load i32*, i32** %9
%39 = call i32 @mustreadword(i32* %38)
%40 = load i32*, i32** %9
%41 = call i32 @mustreadword(i32* %40)
store i32 %41, i32* %17
store i32 0, i32* %18
br label %42
42: ; preds = %49, %37
%43 = load i32, i32* %18
%44 = load i32, i32* %17
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32*, i32** %9
%48 = call i32 @mustreadword(i32* %47)
br label %49
49: ; preds = %46
%50 = load i32, i32* %18
%51 = add nsw i32 %50, 1
store i32 %51, i32* %18
br label %42
52: ; preds = %42
br label %53
53: ; preds = %52, %34
%54 = load i32, i32* @stderr
%55 = load i32, i32* %16
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %55)
store i32 1, i32* %8
br label %108
57: ; preds = %7
%58 = load i32*, i32** %9
%59 = call i32 @mustreadword(i32* %58)
%60 = sdiv i32 %59, 256
%61 = load i32*, i32** %11
store i32 %60, i32* %61
%62 = load i32*, i32** %9
%63 = call i32 @mustreadword(i32* %62)
%64 = sdiv i32 %63, 256
%65 = load i32*, i32** %12
store i32 %64, i32* %65
%66 = load i32*, i32** %9
%67 = call i32 @mustreadword(i32* %66)
%68 = sdiv i32 %67, 256
%69 = load i32*, i32** %13
store i32 %68, i32* %69
%70 = load i32*, i32** %9
%71 = call i32 @mustreadword(i32* %70)
%72 = load i32, i32* %10
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %75
74: ; preds = %57
store i32 0, i32* %8
br label %108
75: ; preds = %57
%76 = load i32*, i32** %9
%77 = call i32 @mustreadword(i32* %76)
%78 = load i32*, i32** %9
%79 = call i32 @mustreadword(i32* %78)
store i32 %79, i32* %17
%80 = load i32, i32* %17
%81 = add nsw i32 %80, -1
store i32 %81, i32* %17
br label %82
82: ; preds = %101, %75
%83 = load i32, i32* %17
%84 = icmp sgt i32 %83, 0
br i1 %84, label %85, label %104
85: ; preds = %82
%86 = load i32*, i32** %9
%87 = call i32 @mustreadword(i32* %86)
store i32 %87, i32* %19
%88 = load i32, i32* %19
%89 = icmp sgt i32 %88, 255
br i1 %89, label %90, label %91
90: ; preds = %85
store i32 32, i32* %19
br label %91
91: ; preds = %90, %85
%92 = load i32, i32* %15
%93 = icmp sgt i32 %92, 1
br i1 %93, label %94, label %101
94: ; preds = %91
%95 = load i32, i32* %19
%96 = trunc i32 %95 to i8
%97 = load i8*, i8** %14
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %14
store i8 %96, i8* %97
%99 = load i32, i32* %15
%100 = add nsw i32 %99, -1
store i32 %100, i32* %15
br label %101
101: ; preds = %94, %91
%102 = load i32, i32* %17
%103 = add nsw i32 %102, -1
store i32 %103, i32* %17
br label %82
104: ; preds = %82
%105 = load i8*, i8** %14
store i8 0, i8* %105
%106 = load i32*, i32** %9
%107 = call i32 @mustreadword(i32* %106)
store i32 0, i32* %8
br label %108
108: ; preds = %104, %74, %53
%109 = load i32, i32* %8
ret i32 %109
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Non RGB color (colorspace %d) skipped\0A\00"
define i32 @convertcolor(i32* %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i8* nocapture writeonly %5, i32 %6) {
%8 = tail call i32 @mustreadword(i32* %0)
%9 = icmp eq i32 %8, 0
%10 = tail call i32 @mustreadword(i32* %0)
br i1 %9, label %28, label %11
11: ; preds = %7
%12 = tail call i32 @mustreadword(i32* %0)
%13 = tail call i32 @mustreadword(i32* %0)
%14 = tail call i32 @mustreadword(i32* %0)
%15 = icmp eq i32 %1, 2
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = tail call i32 @mustreadword(i32* %0)
%18 = tail call i32 @mustreadword(i32* %0)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16, %20
%21 = phi i32 [ %23, %20 ], [ 0, %16 ]
%22 = tail call i32 @mustreadword(i32* %0)
%23 = add nuw nsw i32 %21, 1
%24 = icmp eq i32 %23, %18
br i1 %24, label %25, label %20
25: ; preds = %20, %16, %11
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %60
28: ; preds = %7
%29 = sdiv i32 %10, 256
store i32 %29, i32* %2
%30 = tail call i32 @mustreadword(i32* %0)
%31 = sdiv i32 %30, 256
store i32 %31, i32* %3
%32 = tail call i32 @mustreadword(i32* %0)
%33 = sdiv i32 %32, 256
store i32 %33, i32* %4
%34 = tail call i32 @mustreadword(i32* %0)
%35 = icmp eq i32 %1, 1
br i1 %35, label %60, label %36
36: ; preds = %28
%37 = tail call i32 @mustreadword(i32* %0)
%38 = tail call i32 @mustreadword(i32* %0)
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %57
40: ; preds = %36, %53
%41 = phi i32 [ %44, %53 ], [ %38, %36 ]
%42 = phi i32 [ %55, %53 ], [ %6, %36 ]
%43 = phi i8* [ %54, %53 ], [ %5, %36 ]
%44 = add nsw i32 %41, -1
%45 = tail call i32 @mustreadword(i32* %0)
%46 = icmp sgt i32 %42, 1
br i1 %46, label %47, label %53
47: ; preds = %40
%48 = icmp sgt i32 %45, 255
%49 = trunc i32 %45 to i8
%50 = select i1 %48, i8 32, i8 %49
%51 = getelementptr inbounds i8, i8* %43, i64 1
store i8 %50, i8* %43
%52 = add nsw i32 %42, -1
br label %53
53: ; preds = %47, %40
%54 = phi i8* [ %51, %47 ], [ %43, %40 ]
%55 = phi i32 [ %52, %47 ], [ %42, %40 ]
%56 = icmp ugt i32 %41, 2
br i1 %56, label %40, label %57
57: ; preds = %53, %36
%58 = phi i8* [ %5, %36 ], [ %54, %53 ]
store i8 0, i8* %58
%59 = tail call i32 @mustreadword(i32* %0)
br label %60
60: ; preds = %28, %57, %25
%61 = phi i32 [ 1, %25 ], [ 0, %57 ], [ 0, %28 ]
ret i32 %61
}