#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 */
scalar_t__ check_cmyk(double *);
scalar_t__ check_hsv(double, double, double);
scalar_t__ check_rgb(int *);
int /*<<< orphan*/ cmyk_to_rgb(int *, double *);
int /*<<< orphan*/ hsv_to_rgb(int *, double, double, double);
int slash_count(char *);
int sscanf(char *, char *, ...);
int getrgb(char *line, int rgb[], int color_model) {
  int n, count;
  count = slash_count(line);
  if (count == 3) {
    double cmyk[4];
    n = sscanf(line, "%lf/%lf/%lf/%lf", &cmyk[0], &cmyk[1], &cmyk[2], &cmyk[3]);
    if (n != 4 || check_cmyk(cmyk))
      return (1);
    cmyk_to_rgb(rgb, cmyk);
    return (0);
  }
  if (count == 2) {
    if (color_model == 0) {
      n = sscanf(line, "%d/%d/%d", &rgb[0], &rgb[1], &rgb[2]);
      if (n != 3 || check_rgb(rgb))
        return (1);
    } else {
      double h, s, v;
      n = sscanf(line, "%lf/%lf/%lf", &h, &s, &v);
      if (n != 3 || check_hsv(h, s, v))
        return (1);
      hsv_to_rgb(rgb, h, s, v);
    }
    return (0);
  }
  if (count == 0) {
    n = sscanf(line, "%d", &rgb[0]);
    rgb[1] = rgb[2] = rgb[0];
    if (n != 1 || check_rgb(rgb))
      return (1);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<getrgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <slash_count@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jne    120c <getrgb+0x9c>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x50(%rbp),%rcx
add    $0x8,%rcx
lea    -0x50(%rbp),%r8
add    $0x10,%r8
lea    -0x50(%rbp),%r9
add    $0x18,%r9
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jne    11e7 <getrgb+0x77>
lea    -0x50(%rbp),%rdi
call   1050 <check_cmyk@plt>
cmp    $0x0,%rax
je     11f3 <getrgb+0x83>
movl   $0x1,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <cmyk_to_rgb@plt>
movl   $0x0,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
cmpl   $0x2,-0x24(%rbp)
jne    12f0 <getrgb+0x180>
cmpl   $0x0,-0x1c(%rbp)
jne    1277 <getrgb+0x107>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
add    $0x4,%rcx
mov    -0x18(%rbp),%r8
add    $0x8,%r8
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jne    1266 <getrgb+0xf6>
mov    -0x18(%rbp),%rdi
call   1070 <check_rgb@plt>
cmp    $0x0,%rax
je     1272 <getrgb+0x102>
movl   $0x1,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
jmp    12e4 <getrgb+0x174>
mov    -0x10(%rbp),%rdi
lea    0xd82(%rip),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x68(%rbp),%r8
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jne    12c0 <getrgb+0x150>
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1090 <check_hsv@plt>
cmp    $0x0,%rax
je     12cc <getrgb+0x15c>
movl   $0x1,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
mov    -0x18(%rbp),%rdi
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1030 <hsv_to_rgb@plt>
movl   $0x0,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
cmpl   $0x0,-0x24(%rbp)
jne    135c <getrgb+0x1ec>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
cmpl   $0x1,-0x20(%rbp)
jne    1344 <getrgb+0x1d4>
mov    -0x18(%rbp),%rdi
call   1070 <check_rgb@plt>
cmp    $0x0,%rax
je     1350 <getrgb+0x1e0>
movl   $0x1,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
movl   $0x0,-0x4(%rbp)
jmp    1363 <getrgb+0x1f3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrgb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <slash_count@plt>
mov    $0x1,%r15d
test   %eax,%eax
je     11fc <getrgb+0x8c>
cmp    $0x2,%eax
je     123b <getrgb+0xcb>
cmp    $0x3,%eax
jne    12c9 <getrgb+0x159>
lea    0x18(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x28(%rsp),%r9
lea    0xe47(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sscanf@plt>
mov    $0x1,%r15d
cmp    $0x4,%eax
jne    12c9 <getrgb+0x159>
lea    0x10(%rsp),%rdi
call   1050 <check_cmyk@plt>
test   %rax,%rax
jne    12c9 <getrgb+0x159>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <cmyk_to_rgb@plt>
jmp    12c6 <getrgb+0x156>
lea    0xe13(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
mov    (%r14),%ecx
mov    %ecx,0x8(%r14)
mov    %ecx,0x4(%r14)
cmp    $0x1,%eax
jne    12c9 <getrgb+0x159>
mov    %r14,%rdi
call   1070 <check_rgb@plt>
xor    %r15d,%r15d
test   %rax,%rax
setne  %r15b
jmp    12c9 <getrgb+0x159>
test   %ebp,%ebp
je     1298 <getrgb+0x128>
lea    0xdbe(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    12c9 <getrgb+0x159>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
call   1090 <check_hsv@plt>
test   %rax,%rax
jne    12c9 <getrgb+0x159>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
mov    %r14,%rdi
call   1030 <hsv_to_rgb@plt>
jmp    12c6 <getrgb+0x156>
lea    0x4(%r14),%rcx
lea    0x8(%r14),%r8
lea    0xd69(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    12c9 <getrgb+0x159>
mov    %r14,%rdi
call   1070 <check_rgb@plt>
test   %rax,%rax
jne    12c9 <getrgb+0x159>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%lf/%lf/%lf/%lf\00"
@.str.1 = [9 x i8] c"%d/%d/%d\00"
@.str.2 = [12 x i8] c"%lf/%lf/%lf\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @getrgb(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [4 x double]
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %5
%15 = call i32 @slash_count(i8* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %36
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%21 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 1
%22 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 2
%23 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 3
%24 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double* %20, double* %21, double* %22, double* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 4
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%29 = call i64 @check_cmyk(double* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27, %18
store i32 1, i32* %4
br label %102
32: ; preds = %27
%33 = load i32*, i32** %6
%34 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%35 = call i32 @cmyk_to_rgb(i32* %33, double* %34)
store i32 0, i32* %4
br label %102
36: ; preds = %3
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %78
39: ; preds = %36
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load i8*, i8** %5
%44 = load i32*, i32** %6
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32*, i32** %6
%47 = getelementptr inbounds i32, i32* %46, i64 1
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 2
%50 = call i32 (i8*, i8*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %45, i32* %47, i32* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 3
br i1 %52, label %57, label %53
53: ; preds = %42
%54 = load i32*, i32** %6
%55 = call i64 @check_rgb(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53, %42
store i32 1, i32* %4
br label %102
58: ; preds = %53
br label %77
59: ; preds = %39
%60 = load i8*, i8** %5
%61 = call i32 (i8*, i8*, ...) @sscanf(i8* %60, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double* %11, double* %12, double* %13)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp ne i32 %62, 3
br i1 %63, label %70, label %64
64: ; preds = %59
%65 = load double, double* %11
%66 = load double, double* %12
%67 = load double, double* %13
%68 = call i64 @check_hsv(double %65, double %66, double %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %64, %59
store i32 1, i32* %4
br label %102
71: ; preds = %64
%72 = load i32*, i32** %6
%73 = load double, double* %11
%74 = load double, double* %12
%75 = load double, double* %13
%76 = call i32 @hsv_to_rgb(i32* %72, double %73, double %74, double %75)
br label %77
77: ; preds = %71, %58
store i32 0, i32* %4
br label %102
78: ; preds = %36
%79 = load i32, i32* %9
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %101
81: ; preds = %78
%82 = load i8*, i8** %5
%83 = load i32*, i32** %6
%84 = getelementptr inbounds i32, i32* %83, i64 0
%85 = call i32 (i8*, i8*, ...) @sscanf(i8* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %84)
store i32 %85, i32* %8
%86 = load i32*, i32** %6
%87 = getelementptr inbounds i32, i32* %86, i64 0
%88 = load i32, i32* %87
%89 = load i32*, i32** %6
%90 = getelementptr inbounds i32, i32* %89, i64 2
store i32 %88, i32* %90
%91 = load i32*, i32** %6
%92 = getelementptr inbounds i32, i32* %91, i64 1
store i32 %88, i32* %92
%93 = load i32, i32* %8
%94 = icmp ne i32 %93, 1
br i1 %94, label %99, label %95
95: ; preds = %81
%96 = load i32*, i32** %6
%97 = call i64 @check_rgb(i32* %96)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %95, %81
store i32 1, i32* %4
br label %102
100: ; preds = %95
store i32 0, i32* %4
br label %102
101: ; preds = %78
store i32 1, i32* %4
br label %102
102: ; preds = %101, %100, %99, %77, %70, %57, %32, %31
%103 = load i32, i32* %4
ret i32 %103
}

LLVM IR (-O2):
@.str = [16 x i8] c"%lf/%lf/%lf/%lf\00"
@.str.1 = [9 x i8] c"%d/%d/%d\00"
@.str.2 = [12 x i8] c"%lf/%lf/%lf\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @getrgb(i8* %0, i32* %1, i32 %2) {
%4 = alloca [4 x double]
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = tail call i32 @slash_count(i8* %0)
switch i32 %8, label %63 [
i32 3, label %9
i32 2, label %24
i32 0, label %53
]
9: ; preds = %3
%10 = bitcast [4 x double]* %4 to i8*
%11 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%12 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%13 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%14 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%15 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double* %11, double* %12, double* %13, double* %14)
%16 = icmp eq i32 %15, 4
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = call i64 @check_cmyk(double* %11)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @cmyk_to_rgb(i32* %1, double* %11)
br label %22
22: ; preds = %9, %17, %20
%23 = phi i32 [ 0, %20 ], [ 1, %17 ], [ 1, %9 ]
br label %63
24: ; preds = %3
%25 = icmp eq i32 %2, 0
br i1 %25, label %26, label %34
26: ; preds = %24
%27 = getelementptr inbounds i32, i32* %1, i64 1
%28 = getelementptr inbounds i32, i32* %1, i64 2
%29 = tail call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %27, i32* %28)
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %63
31: ; preds = %26
%32 = tail call i64 @check_rgb(i32* %1)
%33 = icmp eq i64 %32, 0
br i1 %33, label %52, label %63
34: ; preds = %24
%35 = bitcast double* %5 to i8*
%36 = bitcast double* %6 to i8*
%37 = bitcast double* %7 to i8*
%38 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double* %5, double* %6, double* %7)
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = load double, double* %5
%42 = load double, double* %6
%43 = load double, double* %7
%44 = call i64 @check_hsv(double %41, double %42, double %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load double, double* %5
%48 = load double, double* %6
%49 = load double, double* %7
%50 = call i32 @hsv_to_rgb(i32* %1, double %47, double %48, double %49)
br label %52
51: ; preds = %34, %40
br label %63
52: ; preds = %46, %31
br label %63
53: ; preds = %3
%54 = tail call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%55 = load i32, i32* %1
%56 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %55, i32* %56
%57 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %55, i32* %57
%58 = icmp eq i32 %54, 1
br i1 %58, label %59, label %63
59: ; preds = %53
%60 = tail call i64 @check_rgb(i32* %1)
%61 = icmp ne i64 %60, 0
%62 = zext i1 %61 to i32
br label %63
63: ; preds = %59, %3, %53, %51, %26, %31, %52, %22
%64 = phi i32 [ %23, %22 ], [ 0, %52 ], [ 1, %51 ], [ 1, %31 ], [ 1, %26 ], [ 1, %53 ], [ 1, %3 ], [ %62, %59 ]
ret i32 %64
}