#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 hd_driveid {
  char *model;
  char *fw_rev;
  char *serial_no;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ HDIO_GET_IDENTITY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct hd_driveid *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read_proc_identify(char *, struct hd_driveid *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  struct hd_driveid id;
  if (argc != 2) {
    fprintf(stderr, "usage: %s [device]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (read_proc_identify(argv[1], &id) != 0) {
    fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
      perror("open() failed");
      exit(1);
    }
    if (ioctl(fd, HDIO_GET_IDENTITY, &id) != 0) {
      perror("could not get IDE device info");
      exit(1);
    }
  }
  printf("MODEL=\"%.40s\"\n", id.model);
  printf("FW_REV=\"%.8s\"\n", id.fw_rev);
  printf("SERIAL_NO=\"%.20s\"\n", id.serial_no);
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <read_proc_identify@plt>
cmp    $0x0,%rax
je     1248 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120e <main+0x9e>
lea    0xe15(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1243 <main+0xd3>
lea    0xdee(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1248 <main+0xd8>
mov    -0x30(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ca <main+0x5a>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1030 <read_proc_identify@plt>
test   %rax,%rax
jne    11f0 <main+0x80>
mov    0x8(%rsp),%rsi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
jns    120f <main+0x9f>
lea    0xe07(%rip),%rdi
jmp    1234 <main+0xc4>
mov    0x2dca(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1050 <ioctl@plt>
test   %rax,%rax
je     1190 <main+0x20>
lea    0xdee(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hd_driveid = type { i8*, i8*, i8* }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s [device]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"open() failed\00"
@HDIO_GET_IDENTITY = global i32 0
@.str.2 = [30 x i8] c"could not get IDE device info\00"
@.str.3 = [15 x i8] c"MODEL=\22%.40s\22\0A\00"
@.str.4 = [15 x i8] c"FW_REV=\22%.8s\22\0A\00"
@.str.5 = [19 x i8] c"SERIAL_NO=\22%.20s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hd_driveid
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @read_proc_identify(i8* %21, %struct.hd_driveid* %7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %24
%36 = load i32, i32* %6
%37 = load i32, i32* @HDIO_GET_IDENTITY
%38 = call i64 @ioctl(i32 %36, i32 %37, %struct.hd_driveid* %7)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %35
br label %44
44: ; preds = %43, %18
%45 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %7, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %7, i32 0, i32 1
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %7, i32 0, i32 2
%52 = load i8*, i8** %51
%53 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.hd_driveid = type { i8*, i8*, i8* }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s [device]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"open() failed\00"
@HDIO_GET_IDENTITY = global i32 0
@.str.2 = [30 x i8] c"could not get IDE device info\00"
@.str.3 = [15 x i8] c"MODEL=\22%.40s\22\0A\00"
@.str.4 = [15 x i8] c"FW_REV=\22%.8s\22\0A\00"
@.str.5 = [19 x i8] c"SERIAL_NO=\22%.20s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.hd_driveid
%4 = bitcast %struct.hd_driveid* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @read_proc_identify(i8* %14, %struct.hd_driveid* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = load i32, i32* @HDIO_GET_IDENTITY
%27 = call i64 @ioctl(i32 %20, i32 %26, %struct.hd_driveid* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25, %12
%33 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %3, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %3, i64 0, i32 1
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds %struct.hd_driveid, %struct.hd_driveid* %3, i64 0, i32 2
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 0)
unreachable
}