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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ system(char *);
int is_loop_partition(char *dev) {
  int ret = 0;
  int i = 0;
  char diskname[4], cmd[128], buf[256];
  FILE *fp;
  memset(cmd, 0, 128);
  memset(buf, 0, 256);
  strncpy(diskname, dev, 3);
  diskname[3] = '\0';
  snprintf(cmd, sizeof(cmd),
           "/usr/sbin/parted -s /dev/%s print | grep \"Partition Table\" | awk "
           "'{print $3}' > "
           "/tmp/disk_loop_partition",
           diskname);
  system(cmd);
  if (!(fp = fopen("/tmp/disk_loop_partition", "r"))) {
    fclose(fp);
    return 0;
  }
  fgets(buf, sizeof(buf), fp);
  fclose(fp);
  i = 0;
  while (buf[i] != '\0' && buf[i] != '\r' && buf[i] != '\n')
    i++;
  buf[i] = '\0';
  if (!strcmp(buf, "loop")) {
    fprintf(stderr, "[is_loop_partition]: Disk %s is a loop partition!\n", dev);
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<is_loop_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
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    $0x80,%esi
lea    0xe00(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <system@plt>
lea    0xe38(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1a8(%rbp)
cmp    $0x0,%rax
jne    124d <is_loop_partition+0xbd>
mov    -0x1a8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1339 <is_loop_partition+0x1a9>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a8(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    -0x1a8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a9(%rbp)
je     12ca <is_loop_partition+0x13a>
movslq -0x18(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x1a9(%rbp)
je     12ca <is_loop_partition+0x13a>
movslq -0x18(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1a9(%rbp)
mov    -0x1a9(%rbp),%al
test   $0x1,%al
jne    12dd <is_loop_partition+0x14d>
jmp    12eb <is_loop_partition+0x15b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1278 <is_loop_partition+0xe8>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x1a0(%rbp,%rax,1)
lea    -0x1a0(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1333 <is_loop_partition+0x1a3>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd49(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_loop_partition>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %rdi,%r14
lea    0x110(%rsp),%r12
xor    %r15d,%r15d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
lea    0xe23(%rip),%rdx
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1050 <system@plt>
lea    0xe54(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1291 <is_loop_partition+0x111>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
mov    $0x2401,%ecx
jmp    1244 <is_loop_partition+0xc4>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl 0x10(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     1240 <is_loop_partition+0xc0>
bt     %rdx,%rcx
jae    1240 <is_loop_partition+0xc0>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    $0x706f6f6c,%eax
xor    0x10(%rsp),%eax
movzbl 0x14(%rsp),%ecx
xor    %r15d,%r15d
or     %eax,%ecx
jne    1298 <is_loop_partition+0x118>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    %r14,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%r15d
jmp    1298 <is_loop_partition+0x118>
xor    %edi,%edi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [105 x i8] c"/usr/sbin/parted -s /dev/%s print | grep \22Partition Table\22 | awk '{print $3}' > /tmp/disk_loop_partition\00"
@.str.1 = [25 x i8] c"/tmp/disk_loop_partition\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"loop\00"
@stderr = global i32 0
@.str.4 = [51 x i8] c"[is_loop_partition]: Disk %s is a loop partition!\0A\00"
define i32 @is_loop_partition(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = alloca [128 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32*
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 128)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 256)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 3)
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %17
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%20 = call i32 @snprintf(i8* %18, i32 128, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %1
%26 = load i32*, i32** %9
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %2
br label %73
28: ; preds = %1
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = load i32*, i32** %9
%31 = call i32 @fgets(i8* %29, i32 256, i32* %30)
%32 = load i32*, i32** %9
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %5
br label %34
34: ; preds = %57, %28
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %34
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 13
br i1 %47, label %48, label %55
48: ; preds = %41
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 10
br label %55
55: ; preds = %48, %41, %34
%56 = phi i1 [ false, %41 ], [ false, %34 ], [ %54, %48 ]
br i1 %56, label %57, label %60
57: ; preds = %55
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %34
60: ; preds = %55
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %62
store i8 0, i8* %63
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%65 = call i32 @strcmp(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %3
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %69)
store i32 1, i32* %4
br label %71
71: ; preds = %67, %60
%72 = load i32, i32* %4
store i32 %72, i32* %2
br label %73
73: ; preds = %71, %25
%74 = load i32, i32* %2
ret i32 %74
}

LLVM IR (-O2):
@.str = [105 x i8] c"/usr/sbin/parted -s /dev/%s print | grep \22Partition Table\22 | awk '{print $3}' > /tmp/disk_loop_partition\00"
@.str.1 = [25 x i8] c"/tmp/disk_loop_partition\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"loop\00"
@stderr = global i32 0
@.str.4 = [51 x i8] c"[is_loop_partition]: Disk %s is a loop partition!\0A\00"
define i32 @is_loop_partition(i8* %0) {
%2 = alloca [4 x i8]
%3 = alloca [128 x i8]
%4 = alloca [256 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 [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %6, i32 0, i32 128)
%9 = call i32 @memset(i8* %7, i32 0, i32 256)
%10 = call i32 @strncpy(i8* %5, i8* %0, i32 3)
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %11
%12 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = call i32 @system(i8* %6)
%14 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @fclose(i32* null)
br label %35
18: ; preds = %1
%19 = call i32 @fgets(i8* %7, i32 256, i32* %14)
%20 = call i32 @fclose(i32* %14)
br label %21
21: ; preds = %25, %18
%22 = phi i64 [ %26, %25 ], [ 0, %18 ]
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %22
%24 = load i8, i8* %23
switch i8 %24, label %25 [
i8 0, label %27
i8 13, label %27
i8 10, label %27
]
25: ; preds = %21
%26 = add nuw i64 %22, 1
br label %21
27: ; preds = %21, %21, %21
%28 = and i64 %22, 4294967295
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i32 @bcmp(i8* dereferenceable(5) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %35
35: ; preds = %27, %32, %16
%36 = phi i32 [ 0, %16 ], [ 0, %27 ], [ 1, %32 ]
ret i32 %36
}