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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int is_noshare_partition(char *dev) {
  FILE *fp;
  char diskname[4], cmd[128], result[8];
  if (strlen(dev) != 4)
    return 0;
  strncpy(diskname, dev, 3);
  diskname[3] = '\0';
  snprintf(cmd, sizeof(cmd),
           "/usr/sbin/parted -s /dev/%s print noshare | grep %s", diskname,
           dev);
  fp = popen(cmd, "r");
  if (!fp) {
    perror("popen");
    return 0;
  }
  memset(result, 0, sizeof(result));
  fgets(result, sizeof(result), fp);
  pclose(fp);
  return strlen(result) >= 4 ? 1 : 0;
}


x86 assembly (clang, -O0):
<is_noshare_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
je     11ad <is_noshare_partition+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    126c <is_noshare_partition+0xec>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x19(%rbp)
lea    -0xa0(%rbp),%rdi
lea    -0x1c(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x80,%esi
lea    0xe22(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121d <is_noshare_partition+0x9d>
lea    0xe2a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    126c <is_noshare_partition+0xec>
lea    -0xa8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0xa8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x8,%esi
call   1080 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
lea    -0xa8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x4,%edx
cmovge %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_noshare_partition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
jne    122d <is_noshare_partition+0xad>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
lea    0xe3f(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1060 <snprintf@plt>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     123d <is_noshare_partition+0xbd>
mov    %rax,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
setge  %bpl
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf2(%rip),%rdi
call   10a0 <perror@plt>
jmp    122d <is_noshare_partition+0xad>

LLVM IR (-O0):
@.str = [52 x i8] c"/usr/sbin/parted -s /dev/%s print noshare | grep %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"popen\00"
define i32 @is_noshare_partition(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4 x i8]
%6 = alloca [128 x i8]
%7 = alloca [8 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %40
12: ; preds = %1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 3)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 0, i8* %16
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @snprintf(i8* %17, i32 128, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = call i32* @popen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %4
%23 = load i32*, i32** %4
%24 = icmp ne i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %12
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %40
27: ; preds = %12
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 8)
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %4
%32 = call i32 @fgets(i8* %30, i32 8, i32* %31)
%33 = load i32*, i32** %4
%34 = call i32 @pclose(i32* %33)
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = icmp sge i32 %36, 4
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 1, i32 0
store i32 %39, i32* %2
br label %40
40: ; preds = %27, %25, %11
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [52 x i8] c"/usr/sbin/parted -s /dev/%s print noshare | grep %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"popen\00"
define i32 @is_noshare_partition(i8* %0) {
%2 = alloca [4 x i8]
%3 = alloca [128 x i8]
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = call i32 @strncpy(i8* %5, i8* %0, i32 3)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %12
%13 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %0)
%14 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %25
18: ; preds = %10
%19 = call i32 @memset(i8* %7, i32 0, i32 8)
%20 = call i32 @fgets(i8* %7, i32 8, i32* %14)
%21 = call i32 @pclose(i32* %14)
%22 = call i32 @strlen(i8* %7)
%23 = icmp sgt i32 %22, 3
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %1, %18, %16
%26 = phi i32 [ %24, %18 ], [ 0, %16 ], [ 0, %1 ]
ret i32 %26
}