#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  char interface_id;
  int cmd_len;
  unsigned char *dxferp;
  unsigned char *cmdp;
  unsigned char *sbp;
  int /*<<< orphan*/ *usr_ptr;
  int /*<<< orphan*/ pack_id;
  int /*<<< orphan*/ flags;
  int /*<<< orphan*/ timeout;
  int /*<<< orphan*/ dxfer_len;
  int /*<<< orphan*/ iovec_count;
  int /*<<< orphan*/ mx_sb_len;
  int /*<<< orphan*/ dxfer_direction;
};
typedef TYPE_1__ sg_io_hdr_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SG_DXFER_NONE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, TYPE_1__ *, int);
int /*<<< orphan*/ stderr;
int write(int, TYPE_1__ *, int);
int main(int argc, char **argv) {
  int fd;
  unsigned char cmd[] = {0x2b, 0x00, 0x00, 0x00, 0x00, 0x00};
  unsigned char sb[32];
  unsigned char dxfer[32];
  sg_io_hdr_t iohdr = {
      .interface_id = 'S',
      .dxfer_direction = SG_DXFER_NONE,
      .cmd_len = sizeof cmd,
      .mx_sb_len = 0,
      .iovec_count = 0,
      .dxfer_len = 0,
      .dxferp = dxfer,
      .cmdp = cmd,
      .sbp = sb,
      .timeout = 0,
      .flags = 0,
      .pack_id = 0,
      .usr_ptr = NULL,
  };
  if (argc != 2) {
    fprintf(stderr, "usage: %s DEVICE\n", argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    err(1, "%s", argv[1]);
  }
  if (write(fd, &iohdr, sizeof iohdr) != sizeof iohdr) {
    err(1, "write");
  }
  read(fd, &iohdr, sizeof iohdr);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe81(%rip),%eax
mov    %eax,-0x1a(%rbp)
mov    0xe7b(%rip),%ax
mov    %ax,-0x16(%rbp)
movb   $0x53,-0xa8(%rbp)
movl   $0x6,-0xa4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x1a(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x90(%rbp)
movq   $0x0,-0x88(%rbp)
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1232 <main+0xd2>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde5(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x166>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1270 <main+0x110>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%edi
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
mov    -0x14(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x48,%edx
call   1030 <write@plt>
cltq
cmp    $0x48,%rax
je     12a3 <main+0x143>
mov    $0x1,%edi
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1070 <err@plt>
mov    -0x14(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x48,%edx
call   1050 <read@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
movw   $0x0,0x4(%rsp)
movl   $0x2b,(%rsp)
movb   $0x53,0x8(%rsp)
movl   $0x6,0xc(%rsp)
lea    0x50(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rax
mov    %rax,0x18(%rsp)
lea    0x70(%rsp),%rax
mov    %rax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movups %xmm0,0x38(%rsp)
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
cmp    $0x2,%edi
jne    1236 <main+0xd6>
mov    0x8(%rbx),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11f1 <main+0x91>
mov    0x8(%rbx),%rdx
lea    0xe33(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x48,%edx
call   1030 <write@plt>
cmp    $0x48,%eax
je     121a <main+0xba>
lea    0xe0d(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <err@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x48,%edx
call   1050 <read@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    1253 <main+0xf3>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdbd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8, i32, i8*, i8*, i8*, i32*, i32, i32, i32, i32, i32, i32, i32 }
@__const.main.cmd = [6 x i8] c"+\00\00\00\00\00"
@SG_DXFER_NONE = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s DEVICE\0A\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [6 x i8]
%8 = alloca [32 x i8]
%9 = alloca [32 x i8]
%10 = alloca %struct.TYPE_4__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [6 x i8]* %7 to i8*
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
store i8 83, i8* %12
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 1
store i32 6, i32* %13
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 2
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
store i8* %15, i8** %14
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 3
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
store i8* %17, i8** %16
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 4
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
store i8* %19, i8** %18
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 5
store i32* null, i32** %20
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 6
store i32 0, i32* %21
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 7
store i32 0, i32* %22
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 8
store i32 0, i32* %23
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 9
store i32 0, i32* %24
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 10
store i32 0, i32* %25
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 11
store i32 0, i32* %26
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 12
%28 = load i32, i32* @SG_DXFER_NONE
store i32 %28, i32* %27
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 2
br i1 %30, label %31, label %37
31: ; preds = %2
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %62
37: ; preds = %2
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDWR
%42 = call i32 @open(i8* %40, i32 %41)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %37
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %45, %37
%51 = load i32, i32* %6
%52 = call i32 @write(i32 %51, %struct.TYPE_4__* %10, i32 72)
%53 = sext i32 %52 to i64
%54 = icmp ne i64 %53, 72
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %50
%58 = load i32, i32* %6
%59 = call i32 @read(i32 %58, %struct.TYPE_4__* %10, i32 72)
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
store i32 0, i32* %3
br label %62
62: ; preds = %57, %31
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8, i32, i8*, i8*, i8*, i32*, i32, i32, i32, i32, i32, i32, i32 }
@__const.main.cmd = [6 x i8] c"+\00\00\00\00\00"
@SG_DXFER_NONE = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s DEVICE\0A\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca %struct.TYPE_4__
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 0
store i8 83, i8* %10
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 1
store i32 6, i32* %11
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 2
store i8* %9, i8** %12
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 3
store i8* %7, i8** %13
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 4
store i8* %8, i8** %14
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 5
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 12
%17 = bitcast i32** %15 to i8*
%18 = load i32, i32* @SG_DXFER_NONE
store i32 %18, i32* %16
%19 = icmp eq i32 %0, 2
br i1 %19, label %24, label %20
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %41
24: ; preds = %2
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* %26, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %25
%32 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %24
%34 = call i32 @write(i32 %28, %struct.TYPE_4__* %6, i32 72)
%35 = icmp eq i32 %34, 72
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = call i32 @read(i32 %28, %struct.TYPE_4__* %6, i32 72)
%40 = call i32 @close(i32 %28)
br label %41
41: ; preds = %38, %20
%42 = phi i32 [ 1, %20 ], [ 0, %38 ]
ret i32 %42
}