#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 */
struct printer_ops_s {
  int dummy;
};

/* Variables and functions */
char *capt_identify();
int /*<<< orphan*/ exit(int);
struct printer_ops_s *find_ops(char const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ ieee_isspace(char const);
int /*<<< orphan*/ memcmp(char const *, char *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
const struct printer_ops_s *printer_detect(void) {
  const char *ieee;
  const char *pos;
  const char *end;
  ieee = capt_identify();
  pos = ieee;
  for (; *pos && ieee_isspace(*pos); ++pos)
    ;
  end = pos + strlen(pos);
  for (; end != ieee && ieee_isspace(*(end - 1)); --end)
    ;
  while (pos != end) {
    const char *delim;
    const char *colon;
    for (delim = pos; delim != end && *delim != ';'; ++delim)
      ;
    for (colon = pos; colon != delim && *colon != ':'; ++colon)
      ;
    if (colon != delim) {
      size_t klen = colon - pos;
      if ((klen == 5 && !memcmp(pos, "MODEL", 5)) ||
          (klen == 3 && !memcmp(pos, "MDL", 3))) {
        const struct printer_ops_s *ret;
        ret = find_ops(colon + 1, delim - colon - 1);
        if (ret)
          return ret;
        break;
      }
    }
    if (delim == end)
      break;
    pos = delim + 1;
  }
  fprintf(stderr, "ERROR: CAPT: unknown printer '%s'\n", ieee);
  exit(1);
}


x86 assembly (clang, -O0):
<printer_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x0,%al
call   1040 <capt_identify@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11b6 <printer_detect+0x46>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1090 <ieee_isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c6 <printer_detect+0x56>
jmp    11dc <printer_detect+0x6c>
jmp    11cb <printer_detect+0x5b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118b <printer_detect+0x1b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x49(%rbp)
je     1227 <printer_detect+0xb7>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1090 <ieee_isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1237 <printer_detect+0xc7>
jmp    124d <printer_detect+0xdd>
jmp    123c <printer_detect+0xcc>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11fd <printer_detect+0x8d>
jmp    1252 <printer_detect+0xe2>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     13d6 <printer_detect+0x266>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x4a(%rbp)
je     128b <printer_detect+0x11b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
setne  %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    129b <printer_detect+0x12b>
jmp    12b1 <printer_detect+0x141>
jmp    12a0 <printer_detect+0x130>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1268 <printer_detect+0xf8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x4b(%rbp)
je     12dc <printer_detect+0x16c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x4b(%rbp)
mov    -0x4b(%rbp),%al
test   $0x1,%al
jne    12ec <printer_detect+0x17c>
jmp    1302 <printer_detect+0x192>
jmp    12f1 <printer_detect+0x181>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12b9 <printer_detect+0x149>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     13b2 <printer_detect+0x242>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x5,-0x30(%rbp)
jne    1348 <printer_detect+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xccb(%rip),%rsi
mov    $0x5,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
je     1371 <printer_detect+0x201>
cmpq   $0x3,-0x30(%rbp)
jne    13ad <printer_detect+0x23d>
mov    -0x10(%rbp),%rdi
lea    0xca8(%rip),%rsi
mov    $0x3,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    13ad <printer_detect+0x23d>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%esi
call   1030 <find_ops@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13a8 <printer_detect+0x238>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret
jmp    13d6 <printer_detect+0x266>
jmp    13b2 <printer_detect+0x242>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    13c5 <printer_detect+0x255>
jmp    13d6 <printer_detect+0x266>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1252 <printer_detect+0xe2>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xc20(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<printer_detect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <capt_identify@plt>
mov    %rax,%r15
mov    (%rax),%al
mov    %r15,%r14
test   %al,%al
je     11ba <printer_detect+0x4a>
mov    %r15,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1090 <ieee_isspace@plt>
test   %rax,%rax
je     11ba <printer_detect+0x4a>
movzbl 0x1(%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    11a0 <printer_detect+0x30>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
add    %r14,%rbp
nopl   0x0(%rax,%rax,1)
cmp    %r15,%rbp
je     11ed <printer_detect+0x7d>
movsbl -0x1(%rbp),%edi
add    $0xffffffffffffffff,%rbp
call   1090 <ieee_isspace@plt>
test   %rax,%rax
jne    11d0 <printer_detect+0x60>
add    $0x1,%rbp
jmp    121f <printer_detect+0xaf>
mov    %r15,%rbp
jmp    121f <printer_detect+0xaf>
mov    %r14,%rdi
lea    0xe0a(%rip),%rsi
mov    $0x3,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     1294 <printer_detect+0x124>
add    $0x1,%r13
mov    %r13,%r14
cmp    $0x3b,%r12b
jne    12bf <printer_detect+0x14f>
cmp    %rbp,%r14
je     12bf <printer_detect+0x14f>
mov    %r14,%r13
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13),%r12d
cmp    $0x3b,%r12b
je     1247 <printer_detect+0xd7>
add    $0x1,%r13
cmp    %rbp,%r13
jne    1230 <printer_detect+0xc0>
mov    %rbp,%r13
cmp    %r13,%r14
je     120e <printer_detect+0x9e>
xor    %ebx,%ebx
xchg   %ax,%ax
cmpb   $0x3a,(%r14,%rbx,1)
je     1270 <printer_detect+0x100>
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    %r13,%rax
jne    1250 <printer_detect+0xe0>
jmp    120e <printer_detect+0x9e>
nopw   0x0(%rax,%rax,1)
cmp    $0x3,%rbx
je     11f2 <printer_detect+0x82>
cmp    $0x5,%rbx
jne    120e <printer_detect+0x9e>
mov    %r14,%rdi
lea    0xd76(%rip),%rsi
mov    $0x5,%edx
jmp    1201 <printer_detect+0x91>
lea    (%r14,%rbx,1),%rdi
add    $0x1,%rdi
sub    %r14d,%r13d
not    %ebx
add    %r13d,%ebx
mov    %ebx,%esi
call   1030 <find_ops@plt>
test   %rax,%rax
je     12bf <printer_detect+0x14f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.printer_ops_s = type { i32 }
@.str = [6 x i8] c"MODEL\00"
@.str.1 = [4 x i8] c"MDL\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"ERROR: CAPT: unknown printer '%s'\0A\00"
define %struct.printer_ops_s* @printer_detect() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.printer_ops_s*
%8 = call i8* (...) @capt_identify()
store i8* %8, i8** %1
%9 = load i8*, i8** %1
store i8* %9, i8** %2
br label %10
10: ; preds = %23, %0
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call i64 @ieee_isspace(i8 signext %17)
%19 = icmp ne i64 %18, 0
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ false, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %26
22: ; preds = %20
br label %23
23: ; preds = %22
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %2
br label %10
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = load i8*, i8** %2
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8* %31, i8** %3
br label %32
32: ; preds = %45, %26
%33 = load i8*, i8** %3
%34 = load i8*, i8** %1
%35 = icmp ne i8* %33, %34
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = load i8, i8* %38
%40 = call i64 @ieee_isspace(i8 signext %39)
%41 = icmp ne i64 %40, 0
br label %42
42: ; preds = %36, %32
%43 = phi i1 [ false, %32 ], [ %41, %36 ]
br i1 %43, label %44, label %48
44: ; preds = %42
br label %45
45: ; preds = %44
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %3
br label %32
48: ; preds = %42
br label %49
49: ; preds = %132, %48
%50 = load i8*, i8** %2
%51 = load i8*, i8** %3
%52 = icmp ne i8* %50, %51
br i1 %52, label %53, label %135
53: ; preds = %49
%54 = load i8*, i8** %2
store i8* %54, i8** %4
br label %55
55: ; preds = %67, %53
%56 = load i8*, i8** %4
%57 = load i8*, i8** %3
%58 = icmp ne i8* %56, %57
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i8*, i8** %4
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 59
br label %64
64: ; preds = %59, %55
%65 = phi i1 [ false, %55 ], [ %63, %59 ]
br i1 %65, label %66, label %70
66: ; preds = %64
br label %67
67: ; preds = %66
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %4
br label %55
70: ; preds = %64
%71 = load i8*, i8** %2
store i8* %71, i8** %5
br label %72
72: ; preds = %84, %70
%73 = load i8*, i8** %5
%74 = load i8*, i8** %4
%75 = icmp ne i8* %73, %74
br i1 %75, label %76, label %81
76: ; preds = %72
%77 = load i8*, i8** %5
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 58
br label %81
81: ; preds = %76, %72
%82 = phi i1 [ false, %72 ], [ %80, %76 ]
br i1 %82, label %83, label %87
83: ; preds = %81
br label %84
84: ; preds = %83
%85 = load i8*, i8** %5
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %5
br label %72
87: ; preds = %81
%88 = load i8*, i8** %5
%89 = load i8*, i8** %4
%90 = icmp ne i8* %88, %89
br i1 %90, label %91, label %127
91: ; preds = %87
%92 = load i8*, i8** %5
%93 = load i8*, i8** %2
%94 = ptrtoint i8* %92 to i64
%95 = ptrtoint i8* %93 to i64
%96 = sub i64 %94, %95
store i64 %96, i64* %6
%97 = load i64, i64* %6
%98 = icmp eq i64 %97, 5
br i1 %98, label %99, label %103
99: ; preds = %91
%100 = load i8*, i8** %2
%101 = call i32 @memcmp(i8* %100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %110
103: ; preds = %99, %91
%104 = load i64, i64* %6
%105 = icmp eq i64 %104, 3
br i1 %105, label %106, label %126
106: ; preds = %103
%107 = load i8*, i8** %2
%108 = call i32 @memcmp(i8* %107, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%109 = icmp ne i32 %108, 0
br i1 %109, label %126, label %110
110: ; preds = %106, %99
%111 = load i8*, i8** %5
%112 = getelementptr inbounds i8, i8* %111, i64 1
%113 = load i8*, i8** %4
%114 = load i8*, i8** %5
%115 = ptrtoint i8* %113 to i64
%116 = ptrtoint i8* %114 to i64
%117 = sub i64 %115, %116
%118 = sub nsw i64 %117, 1
%119 = trunc i64 %118 to i32
%120 = call %struct.printer_ops_s* @find_ops(i8* %112, i32 %119)
store %struct.printer_ops_s* %120, %struct.printer_ops_s** %7
%121 = load %struct.printer_ops_s*, %struct.printer_ops_s** %7
%122 = icmp ne %struct.printer_ops_s* %121, null
br i1 %122, label %123, label %125
123: ; preds = %110
%124 = load %struct.printer_ops_s*, %struct.printer_ops_s** %7
ret %struct.printer_ops_s* %124
125: ; preds = %110
br label %135
126: ; preds = %106, %103
br label %127
127: ; preds = %126, %87
%128 = load i8*, i8** %4
%129 = load i8*, i8** %3
%130 = icmp eq i8* %128, %129
br i1 %130, label %131, label %132
131: ; preds = %127
br label %135
132: ; preds = %127
%133 = load i8*, i8** %4
%134 = getelementptr inbounds i8, i8* %133, i64 1
store i8* %134, i8** %2
br label %49
135: ; preds = %131, %125, %49
%136 = load i32, i32* @stderr
%137 = load i8*, i8** %1
%138 = call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %137)
%139 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.printer_ops_s = type { i32 }
@.str = [6 x i8] c"MODEL\00"
@.str.1 = [4 x i8] c"MDL\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"ERROR: CAPT: unknown printer '%s'\0A\00"
define %struct.printer_ops_s* @printer_detect() {
%1 = tail call i8* (...) @capt_identify()
%2 = load i8, i8* %1
%3 = icmp eq i8 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %0, %9
%5 = phi i8 [ %11, %9 ], [ %2, %0 ]
%6 = phi i8* [ %10, %9 ], [ %1, %0 ]
%7 = tail call i64 @ieee_isspace(i8 signext %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %9, %0
%14 = phi i8* [ %1, %0 ], [ %10, %9 ], [ %6, %4 ]
%15 = tail call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
br label %18
18: ; preds = %21, %13
%19 = phi i8* [ %17, %13 ], [ %22, %21 ]
%20 = icmp eq i8* %19, %1
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %19, i64 -1
%23 = load i8, i8* %22
%24 = tail call i64 @ieee_isspace(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %18
26: ; preds = %18, %21
%27 = phi i8* [ %1, %18 ], [ %19, %21 ]
%28 = ptrtoint i8* %27 to i64
br label %29
29: ; preds = %72, %26
%30 = phi i8* [ %14, %26 ], [ %73, %72 ]
%31 = ptrtoint i8* %30 to i64
%32 = icmp eq i8* %30, %27
br i1 %32, label %74, label %33
33: ; preds = %29
%34 = getelementptr i8, i8* %30, i64 %28
%35 = sub i64 0, %31
%36 = getelementptr i8, i8* %34, i64 %35
br label %37
37: ; preds = %33, %41
%38 = phi i8* [ %30, %33 ], [ %42, %41 ]
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 59
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = getelementptr inbounds i8, i8* %38, i64 1
%43 = icmp eq i8* %42, %27
br i1 %43, label %44, label %37
44: ; preds = %37, %41
%45 = phi i8* [ %36, %41 ], [ %38, %37 ]
%46 = icmp eq i8* %30, %45
br i1 %46, label %72, label %47
47: ; preds = %44, %51
%48 = phi i8* [ %52, %51 ], [ %30, %44 ]
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 58
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = getelementptr inbounds i8, i8* %48, i64 1
%53 = icmp eq i8* %52, %45
br i1 %53, label %72, label %47
54: ; preds = %47
%55 = ptrtoint i8* %48 to i64
%56 = sub i64 %55, %31
switch i64 %56, label %72 [
i64 5, label %57
i64 3, label %60
]
57: ; preds = %54
%58 = tail call i32 @memcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%59 = icmp eq i32 %58, 0
br i1 %59, label %63, label %72
60: ; preds = %54
%61 = tail call i32 @memcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %72
63: ; preds = %57, %60
%64 = ptrtoint i8* %48 to i64
%65 = getelementptr inbounds i8, i8* %48, i64 1
%66 = ptrtoint i8* %45 to i64
%67 = xor i64 %64, -1
%68 = add i64 %67, %66
%69 = trunc i64 %68 to i32
%70 = tail call %struct.printer_ops_s* @find_ops(i8* %65, i32 %69)
%71 = icmp eq %struct.printer_ops_s* %70, null
br i1 %71, label %74, label %78
72: ; preds = %51, %44, %57, %60, %54
%73 = getelementptr inbounds i8, i8* %45, i64 1
br i1 %40, label %29, label %74
74: ; preds = %72, %29, %63
%75 = load i32, i32* @stderr
%76 = tail call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %63
ret %struct.printer_ops_s* %70
}