#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*/ argp;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IOC(int /*<<< orphan*/, char, int, int);
int /*<<< orphan*/ _IOC_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(int, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int fd;
  unsigned char argp[1024];
  int length;
  --argc;
  ++argv;
  if (argc != 1)
    error(1, "usage: usb_printerid /dev/usb/lp0\n");
  fd = open(argv[0], O_RDWR);
  if (fd < 0)
    error(1, "can't open '%s'\n", argv[0]);
  if (ioctl(fd, _IOC(_IOC_READ, 'P', 1, sizeof(argp)), argp) < 0)
    error(1, "GET_DEVICE_ID on '%s'\n", argv[0]);
  length = (argp[0] << 8) + argp[1] - 2;
  printf("GET_DEVICE_ID string:\n");
  fwrite(argp + 2, 1, length, stdout);
  printf("\n");
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11cb <main+0x4b>
mov    $0x1,%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1207 <main+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    $0x50,%esi
mov    $0x1,%edx
mov    $0x400,%ecx
call   1030 <_IOC@plt>
mov    -0x428(%rbp),%edi
mov    %eax,%esi
lea    -0x420(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1265 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1070 <error@plt>
movzbl -0x420(%rbp),%eax
shl    $0x8,%eax
movzbl -0x41f(%rbp),%ecx
add    %ecx,%eax
sub    $0x2,%eax
mov    %eax,-0x424(%rbp)
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
add    $0x2,%rdi
mov    -0x424(%rbp),%edx
mov    0x2d33(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
lea    0xd7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     11b6 <main+0x26>
lea    0xe56(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <error@plt>
mov    0x8(%r14),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e5 <main+0x55>
mov    0x8(%r14),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <error@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    $0x50,%esi
mov    $0x1,%edx
mov    $0x400,%ecx
call   1050 <_IOC@plt>
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %rax,%rax
jns    122a <main+0x9a>
mov    0x8(%r14),%rdx
lea    0xe16(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <error@plt>
movzwl (%rsp),%ebp
shl    $0x10,%ebp
bswap  %ebp
add    $0xfffffffe,%ebp
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
lea    0x2(%rsp),%rdi
mov    0x2d8a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    %ebp,%edx
call   10b0 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"usage: usb_printerid /dev/usb/lp0\0A\00"
@O_RDWR = global i32 0
@.str.1 = [17 x i8] c"can't open '%s'\0A\00"
@_IOC_READ = global i32 0
@.str.2 = [23 x i8] c"GET_DEVICE_ID on '%s'\0A\00"
@.str.3 = [23 x i8] c"GET_DEVICE_ID string:\0A\00"
@stdout = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i32 1
store i8** %12, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %17
%31 = load i32, i32* %6
%32 = load i32, i32* @_IOC_READ
%33 = call i32 @_IOC(i32 %32, i8 signext 80, i32 1, i32 1024)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = call i64 @ioctl(i32 %31, i32 %33, i8* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %30
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = shl i32 %45, 8
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = add nsw i32 %46, %49
%51 = sub nsw i32 %50, 2
store i32 %51, i32* %8
%52 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = load i32, i32* %8
%56 = load i32, i32* @stdout
%57 = call i32 @fwrite(i8* %54, i32 1, i32 %55, i32 %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [35 x i8] c"usage: usb_printerid /dev/usb/lp0\0A\00"
@O_RDWR = global i32 0
@.str.1 = [17 x i8] c"can't open '%s'\0A\00"
@_IOC_READ = global i32 0
@.str.2 = [23 x i8] c"GET_DEVICE_ID on '%s'\0A\00"
@stdout = global i32 0
@str = [22 x i8] c"GET_DEVICE_ID string:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = tail call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %9
%18 = load i32, i32* @_IOC_READ
%19 = tail call i32 @_IOC(i32 %18, i8 signext 80, i32 1, i32 1024)
%20 = call i64 @ioctl(i32 %12, i32 %19, i8* %4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = call i32 (i32, i8*, ...) @error(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %17
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = shl nuw nsw i32 %27, 8
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = or i32 %28, %31
%33 = add nsw i32 %32, -2
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
%36 = load i32, i32* @stdout
%37 = call i32 @fwrite(i8* %35, i32 1, i32 %33, i32 %36)
%38 = call i32 @putchar(i32 10)
%39 = call i32 @close(i32 %12)
%40 = call i32 @exit(i32 0)
unreachable
}