#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*/ out;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *diop_drive_id(char *blkdev, int page) {
  char *pagename;
  char command[200], out[100], *op, *new;
  FILE *fp;
  int n;
  if (page == 0x83)
    pagename = "--page=0x83";
  else
    pagename = "--page=0x80";
  setenv("PATH", "/sbin:/lib/udev:/bin:/usr/bin:/usr/sbin", 1);
  sprintf(command, "scsi_id --whitelisted --replace-whitespace %s %s", pagename,
          blkdev);
  fp = popen(command, "r");
  if (fp == NULL) {
    fprintf(stderr, "scsi_id command failed for %s\n", blkdev);
    return NULL;
  }
  n = fread(out, 1, sizeof(out), fp);
  if (n < 6) {
    fprintf(stderr, "bogus scsi_id info for %s\n", blkdev);
    return NULL;
  }
  if (out[n - 1] == '\n')
    out[n - 1] = 0;
  op = out;
  if (strncmp(op, "SATA_", 5) == 0)
    op += 5;
  else if (strncmp(op, "1ATA_", 5) == 0)
    op += 5;
  new = malloc(strlen(op) + 1);
  strcpy(new, op);
  return new;
}


x86 assembly (clang, -O0):
<diop_drive_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x83,-0x14(%rbp)
jne    11bf <diop_drive_id+0x2f>
lea    0xe4a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ca <diop_drive_id+0x3a>
lea    0xe46(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe45(%rip),%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe4d(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0xf0(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x178(%rbp)
cmpq   $0x0,-0x178(%rbp)
jne    124b <diop_drive_id+0xbb>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    138d <diop_drive_id+0x1fd>
lea    -0x160(%rbp),%rdi
mov    -0x178(%rbp),%rcx
mov    $0x1,%esi
mov    $0x64,%edx
call   1050 <fread@plt>
mov    %eax,-0x17c(%rbp)
cmpl   $0x6,-0x17c(%rbp)
jge    12a1 <diop_drive_id+0x111>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    138d <diop_drive_id+0x1fd>
mov    -0x17c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x160(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12d0 <diop_drive_id+0x140>
mov    -0x17c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x160(%rbp,%rax,1)
lea    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rdi
lea    0xdc6(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1317 <diop_drive_id+0x187>
mov    -0x168(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x168(%rbp)
jmp    1350 <diop_drive_id+0x1c0>
mov    -0x168(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    134b <diop_drive_id+0x1bb>
mov    -0x168(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x168(%rbp)
jmp    1350 <diop_drive_id+0x1c0>
mov    -0x168(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x170(%rbp)
mov    -0x170(%rbp),%rdi
mov    -0x168(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x170(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diop_drive_id>:
push   %r15
push   %r14
push   %rbx
sub    $0x140,%rsp
mov    %rdi,%r14
cmp    $0x83,%esi
lea    0xe54(%rip),%rax
lea    0xe59(%rip),%rbx
cmove  %rax,%rbx
lea    0xe5a(%rip),%rdi
lea    0xe58(%rip),%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
lea    0xe6f(%rip),%rsi
lea    0x70(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10b0 <sprintf@plt>
lea    0xe86(%rip),%rsi
mov    %r15,%rdi
call   10a0 <popen@plt>
test   %rax,%rax
je     1229 <diop_drive_id+0x99>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmp    $0x5,%eax
jg     1245 <diop_drive_id+0xb5>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
jmp    1239 <diop_drive_id+0xa9>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
xor    %ebx,%ebx
jmp    12b4 <diop_drive_id+0x124>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    1252 <diop_drive_id+0xc2>
movb   $0x0,(%rsp,%rax,1)
lea    0xe59(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1290 <diop_drive_id+0x100>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0x5(%rsp),%r15
cmovne %r14,%r15
jmp    1295 <diop_drive_id+0x105>
lea    0x5(%rsp),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"--page=0x83\00"
@.str.1 = [12 x i8] c"--page=0x80\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [40 x i8] c"/sbin:/lib/udev:/bin:/usr/bin:/usr/sbin\00"
@.str.4 = [49 x i8] c"scsi_id --whitelisted --replace-whitespace %s %s\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [31 x i8] c"scsi_id command failed for %s\0A\00"
@.str.7 = [27 x i8] c"bogus scsi_id info for %s\0A\00"
@.str.8 = [6 x i8] c"SATA_\00"
@.str.9 = [6 x i8] c"1ATA_\00"
define i8* @diop_drive_id(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [200 x i8]
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 131
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
br label %17
16: ; preds = %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %17
17: ; preds = %16, %15
%18 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 1)
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %20, i8* %21)
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %24, i32** %11
%25 = load i32*, i32** %11
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %4
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %29)
store i8* null, i8** %3
br label %79
31: ; preds = %17
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%33 = load i32*, i32** %11
%34 = call i32 @fread(i8* %32, i32 1, i32 100, i32* %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 6
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %4
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %39)
store i8* null, i8** %3
br label %79
41: ; preds = %31
%42 = load i32, i32* %12
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* %12
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %49, %41
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
store i8* %55, i8** %9
%56 = load i8*, i8** %9
%57 = call i64 @strncmp(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %9
%61 = getelementptr inbounds i8, i8* %60, i64 5
store i8* %61, i8** %9
br label %70
62: ; preds = %54
%63 = load i8*, i8** %9
%64 = call i64 @strncmp(i8* %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i8*, i8** %9
%68 = getelementptr inbounds i8, i8* %67, i64 5
store i8* %68, i8** %9
br label %69
69: ; preds = %66, %62
br label %70
70: ; preds = %69, %59
%71 = load i8*, i8** %9
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %72, 1
%74 = call i8* @malloc(i64 %73)
store i8* %74, i8** %10
%75 = load i8*, i8** %10
%76 = load i8*, i8** %9
%77 = call i32 @strcpy(i8* %75, i8* %76)
%78 = load i8*, i8** %10
store i8* %78, i8** %3
br label %79
79: ; preds = %70, %37, %27
%80 = load i8*, i8** %3
ret i8* %80
}

LLVM IR (-O2):
@.str = [12 x i8] c"--page=0x83\00"
@.str.1 = [12 x i8] c"--page=0x80\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [40 x i8] c"/sbin:/lib/udev:/bin:/usr/bin:/usr/sbin\00"
@.str.4 = [49 x i8] c"scsi_id --whitelisted --replace-whitespace %s %s\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [31 x i8] c"scsi_id command failed for %s\0A\00"
@.str.7 = [27 x i8] c"bogus scsi_id info for %s\0A\00"
@.str.8 = [6 x i8] c"SATA_\00"
@.str.9 = [6 x i8] c"1ATA_\00"
define i8* @diop_drive_id(i8* %0, i32 %1) {
%3 = alloca [200 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %1, 131
%8 = select i1 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 1)
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %8, i8* %0)
%11 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %45
16: ; preds = %2
%17 = call i32 @fread(i8* %6, i32 1, i32 100, i32* %11)
%18 = icmp slt i32 %17, 6
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %45
22: ; preds = %16
%23 = add nsw i32 %17, -1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %22
store i8 0, i8* %25
br label %29
29: ; preds = %28, %22
%30 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 5
br label %39
34: ; preds = %29
%35 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
%36 = icmp eq i64 %35, 0
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 5
%38 = select i1 %36, i8* %37, i8* %6
br label %39
39: ; preds = %34, %32
%40 = phi i8* [ %33, %32 ], [ %38, %34 ]
%41 = call i64 @strlen(i8* dereferenceable(1) %40)
%42 = add nsw i64 %41, 1
%43 = call i8* @malloc(i64 %42)
%44 = call i32 @strcpy(i8* %43, i8* %40)
br label %45
45: ; preds = %39, %19, %13
%46 = phi i8* [ null, %13 ], [ null, %19 ], [ %43, %39 ]
ret i8* %46
}