#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *, char const *, ...);
int getprintcap(char const *, struct printer *);
int /*<<< orphan*/ init_printer(struct printer *);
int /*<<< orphan*/ pcaperr(int);
int /*<<< orphan*/ warnx(char *, char const *);
void chkprinter(const char *ptrname, struct printer *pp) {
  int status;
  init_printer(pp);
  status = getprintcap(ptrname, pp);
  switch (status) {
  case (-2):
  case (-3):
    errx(1, "%s: %s", ptrname, pcaperr(status));
  case (-1):
    errx(1, "%s: unknown printer", ptrname);
  case 1:
    warnx("%s: unresolved tc= reference(s)", ptrname);
  }
}


x86 assembly (clang, -O0):
<chkprinter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <init_printer@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <getprintcap@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
add    $0x3,%eax
sub    $0x2,%eax
jb     11b2 <chkprinter+0x62>
jmp    1190 <chkprinter+0x40>
mov    -0x18(%rbp),%eax
sub    $0xffffffff,%eax
je     11db <chkprinter+0x8b>
jmp    11a1 <chkprinter+0x51>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11f2 <chkprinter+0xa2>
jmp    1202 <chkprinter+0xb2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <pcaperr@plt>
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x8(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1050 <warnx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chkprinter>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1070 <init_printer@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <getprintcap@plt>
lea    0x3(%rax),%ecx
cmp    $0x2,%ecx
jb     1187 <chkprinter+0x37>
cmp    $0xffffffff,%eax
je     11a6 <chkprinter+0x56>
cmp    $0x1,%eax
je     11bc <chkprinter+0x6c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%edi
call   1060 <pcaperr@plt>
lea    0xe6b(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <errx@plt>
lea    0xe5a(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <errx@plt>
lea    0xe58(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <warnx@plt>

LLVM IR (-O0):
%struct.printer = type { i32 }
@.str = [7 x i8] c"%s: %s\00"
@.str.1 = [20 x i8] c"%s: unknown printer\00"
@.str.2 = [32 x i8] c"%s: unresolved tc= reference(s)\00"
define void @chkprinter(i8* %0, %struct.printer* %1) {
%3 = alloca i8*
%4 = alloca %struct.printer*
%5 = alloca i32
store i8* %0, i8** %3
store %struct.printer* %1, %struct.printer** %4
%6 = load %struct.printer*, %struct.printer** %4
%7 = call i32 @init_printer(%struct.printer* %6)
%8 = load i8*, i8** %3
%9 = load %struct.printer*, %struct.printer** %4
%10 = call i32 @getprintcap(i8* %8, %struct.printer* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
switch i32 %11, label %23 [
i32 -2, label %12
i32 -3, label %12
i32 -1, label %17
i32 1, label %20
]
12: ; preds = %2, %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = call i32 @pcaperr(i32 %14)
%16 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %15)
br label %17
17: ; preds = %2, %12
%18 = load i8*, i8** %3
%19 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %2, %17
%21 = load i8*, i8** %3
%22 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
%struct.printer = type { i32 }
@.str = [7 x i8] c"%s: %s\00"
@.str.1 = [20 x i8] c"%s: unknown printer\00"
@.str.2 = [32 x i8] c"%s: unresolved tc= reference(s)\00"
define void @chkprinter(i8* %0, %struct.printer* %1) {
%3 = tail call i32 @init_printer(%struct.printer* %1)
%4 = tail call i32 @getprintcap(i8* %0, %struct.printer* %1)
switch i32 %4, label %12 [
i32 -2, label %5
i32 -3, label %5
i32 -1, label %8
i32 1, label %10
]
5: ; preds = %2, %2
%6 = tail call i32 @pcaperr(i32 %4)
%7 = tail call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %6)
br label %8
8: ; preds = %2, %5
%9 = tail call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %2, %8
%11 = tail call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %2
ret void
}