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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ isPartitionName(char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ logMessage(int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memmove(char **, char **, int);
scalar_t__ realloc(char **, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strsep(char **, char *);
char **getPartitionsList(char *disk) {
  FILE *f;
  int numfound = 0;
  char **rc = NULL;
  f = fopen("/proc/partitions", "r");
  if (!f) {
    logMessage(40, "getPartitionsList: could not open /proc/partitions");
    return NULL;
  }
  while (1) {
    char *tmpptr, *pptr;
    char tmpstr[4096];
    tmpptr = fgets(tmpstr, sizeof(tmpstr), f);
    if (tmpptr) {
      char *a, *b;
      int toknum = 0;
      a = tmpstr;
      while (1) {
        b = strsep(&a, " \n");
        if (!b)
          break;
        if (!*b)
          continue;
        if (toknum == 0) {
          if (!isdigit(*b))
            break;
        } else if (toknum == 2) {
          if (!strcmp(b, "1"))
            break;
        } else if (toknum == 3) {
          if (!isPartitionName(b))
            break;
          if ((disk != NULL) && (strncmp(disk, b, strlen(disk))))
            break;
          pptr = (char *)malloc(strlen(b) + 7);
          sprintf(pptr, "/dev/%s", b);
          if (!rc) {
            rc = (char **)malloc(2 * sizeof(char *));
            rc[0] = pptr;
            rc[1] = NULL;
          } else {
            int idx;
            rc = (char **)realloc(rc, (numfound + 2) * sizeof(char *));
            idx = 0;
            while (idx < numfound) {
              if (strcmp(pptr, rc[idx]) < 0)
                break;
              idx++;
            }
            if (idx != numfound)
              memmove(rc + idx + 1, rc + idx,
                      (numfound - idx) * sizeof(char *));
            rc[idx] = pptr;
            rc[numfound + 1] = NULL;
          }
          numfound++;
          break;
        }
        toknum++;
      }
    } else {
      break;
    }
  }
  fclose(f);
  return rc;
}


x86 assembly (clang, -O0):
<getPartitionsList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe1f(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123e <getPartitionsList+0x5e>
mov    $0x28,%edi
lea    0xdd6(%rip),%rsi
call   1040 <logMessage@plt>
movq   $0x0,-0x8(%rbp)
jmp    1532 <getPartitionsList+0x352>
jmp    1243 <getPartitionsList+0x63>
lea    -0x1040(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1090 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1517 <getPartitionsList+0x337>
movl   $0x0,-0x1054(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1048(%rbp)
lea    -0x1048(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,-0x1050(%rbp)
cmpq   $0x0,-0x1050(%rbp)
jne    12ac <getPartitionsList+0xcc>
jmp    1512 <getPartitionsList+0x332>
mov    -0x1050(%rbp),%rax
cmpb   $0x0,(%rax)
jne    12c1 <getPartitionsList+0xe1>
jmp    127f <getPartitionsList+0x9f>
cmpl   $0x0,-0x1054(%rbp)
jne    12f0 <getPartitionsList+0x110>
mov    -0x1050(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isdigit@plt>
cmp    $0x0,%eax
jne    12eb <getPartitionsList+0x10b>
jmp    1512 <getPartitionsList+0x332>
jmp    14fe <getPartitionsList+0x31e>
cmpl   $0x2,-0x1054(%rbp)
jne    1324 <getPartitionsList+0x144>
mov    -0x1050(%rbp),%rdi
lea    0xd2d(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    131f <getPartitionsList+0x13f>
jmp    1512 <getPartitionsList+0x332>
jmp    14f9 <getPartitionsList+0x319>
cmpl   $0x3,-0x1054(%rbp)
jne    14f4 <getPartitionsList+0x314>
mov    -0x1050(%rbp),%rdi
call   1030 <isPartitionName@plt>
cmp    $0x0,%eax
jne    134b <getPartitionsList+0x16b>
jmp    1512 <getPartitionsList+0x332>
cmpq   $0x0,-0x10(%rbp)
je     139c <getPartitionsList+0x1bc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x1050(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x1068(%rbp),%rdi
mov    -0x1060(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     139c <getPartitionsList+0x1bc>
jmp    1512 <getPartitionsList+0x332>
mov    -0x1050(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%edi
add    $0x7,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x1050(%rbp),%rdx
lea    0xc72(%rip),%rsi
call   1100 <sprintf@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1402 <getPartitionsList+0x222>
mov    $0x10,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
jmp    14e6 <getPartitionsList+0x306>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10d0 <realloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1058(%rbp)
mov    -0x1058(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1471 <getPartitionsList+0x291>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x1058(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jge    145d <getPartitionsList+0x27d>
jmp    1471 <getPartitionsList+0x291>
mov    -0x1058(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1058(%rbp)
jmp    1427 <getPartitionsList+0x247>
mov    -0x1058(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     14be <getPartitionsList+0x2de>
mov    -0x28(%rbp),%rdi
movslq -0x1058(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x8,%rdi
mov    -0x28(%rbp),%rsi
movslq -0x1058(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%eax
sub    -0x1058(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   10e0 <memmove@plt>
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x1058(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1512 <getPartitionsList+0x332>
jmp    14f9 <getPartitionsList+0x319>
jmp    14fe <getPartitionsList+0x31e>
mov    -0x1054(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1054(%rbp)
jmp    127f <getPartitionsList+0x9f>
jmp    151c <getPartitionsList+0x33c>
jmp    1521 <getPartitionsList+0x341>
jmp    1243 <getPartitionsList+0x63>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPartitionsList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    %rdi,%rbx
lea    0xe29(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     147a <getPartitionsList+0x29a>
mov    %rax,%r12
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     148f <getPartitionsList+0x2af>
mov    %rbx,0x20(%rsp)
lea    0xdf5(%rip),%r13
lea    0x28(%rsp),%rbx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    1279 <getPartitionsList+0x99>
lea    0x30(%rsp),%rbp
mov    0x10(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1496 <getPartitionsList+0x2b6>
mov    %r14d,%r15d
mov    %rbp,0x28(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strsep@plt>
test   %rax,%rax
je     1260 <getPartitionsList+0x80>
movzbl (%rax),%eax
test   %al,%al
je     1290 <getPartitionsList+0xb0>
movsbl %al,%edi
call   1060 <isdigit@plt>
test   %eax,%eax
je     1260 <getPartitionsList+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strsep@plt>
test   %rax,%rax
je     1260 <getPartitionsList+0x80>
cmpb   $0x0,(%rax)
je     12c0 <getPartitionsList+0xe0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strsep@plt>
test   %rax,%rax
je     1260 <getPartitionsList+0x80>
cmpb   $0x0,(%rax)
je     12e0 <getPartitionsList+0x100>
mov    %rax,%rdi
lea    0xd35(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1260 <getPartitionsList+0x80>
mov    %r14,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strsep@plt>
test   %rax,%rax
je     124e <getPartitionsList+0x6e>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     1320 <getPartitionsList+0x140>
mov    %r14,%rdi
call   1030 <isPartitionName@plt>
test   %eax,%eax
je     124e <getPartitionsList+0x6e>
mov    0x20(%rsp),%rbp
test   %rbp,%rbp
je     1374 <getPartitionsList+0x194>
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    124e <getPartitionsList+0x6e>
mov    %r14,%rdi
call   1080 <strlen@plt>
lea    0x7(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xca9(%rip),%rsi
mov    %r14,%rdx
call   1100 <sprintf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     13f1 <getPartitionsList+0x211>
mov    %rbp,0x18(%rsp)
mov    0x10(%rsp),%rbp
lea    0x10(,%rbp,8),%esi
call   10d0 <realloc@plt>
test   %ebp,%ebp
mov    %rax,0x8(%rsp)
jle    1421 <getPartitionsList+0x241>
mov    %rax,%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rsi
mov    0x18(%rsp),%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
js     1423 <getPartitionsList+0x243>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    13d0 <getPartitionsList+0x1f0>
mov    %r15d,%ebp
jmp    1423 <getPartitionsList+0x243>
mov    $0x10,%edi
call   10b0 <malloc@plt>
mov    %rbp,(%rax)
mov    %rax,%rcx
mov    %rax,0x8(%rsp)
movq   $0x0,0x8(%rax)
mov    0x10(%rsp),%r14
add    $0x1,%r14d
lea    0x30(%rsp),%rbp
jmp    1260 <getPartitionsList+0x80>
xor    %ebp,%ebp
mov    %ebp,%r14d
mov    0x10(%rsp),%r15
cmp    %ebp,%r15d
je     144f <getPartitionsList+0x26f>
mov    0x8(%rsp),%rax
lea    (%rax,%r14,8),%rsi
lea    (%rax,%r14,8),%rdi
add    $0x8,%rdi
mov    %r15d,%edx
sub    %r14d,%edx
shl    $0x3,%edx
call   10e0 <memmove@plt>
mov    0x8(%rsp),%rcx
mov    0x18(%rsp),%rax
mov    %rax,(%rcx,%r14,8)
movslq %r15d,%rax
add    $0x1,%r15d
movq   $0x0,0x8(%rcx,%rax,8)
lea    0x30(%rsp),%rbp
mov    %r15,%r14
jmp    1260 <getPartitionsList+0x80>
lea    0xb81(%rip),%rsi
mov    $0x28,%edi
call   1040 <logMessage@plt>
xor    %eax,%eax
jmp    14a3 <getPartitionsList+0x2c3>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/partitions\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [51 x i8] c"getPartitionsList: could not open /proc/partitions\00"
@.str.3 = [3 x i8] c" \0A\00"
@.str.4 = [2 x i8] c"1\00"
@.str.5 = [8 x i8] c"/dev/%s\00"
define i8** @getPartitionsList(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4096 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i8** null, i8*** %6
%14 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %1
%18 = call i32 @logMessage(i32 40, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
store i8** null, i8*** %2
br label %168
19: ; preds = %1
br label %20
20: ; preds = %19, %163
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i8* @fgets(i8* %21, i32 4096, i32* %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %162
26: ; preds = %20
store i32 0, i32* %12
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
store i8* %27, i8** %10
br label %28
28: ; preds = %26, %37, %158
%29 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %29, i8** %11
%30 = load i8*, i8** %11
%31 = icmp ne i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %28
br label %161
33: ; preds = %28
%34 = load i8*, i8** %11
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
br label %28
38: ; preds = %33
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8*, i8** %11
%43 = load i8, i8* %42
%44 = call i32 @isdigit(i8 signext %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %41
br label %161
47: ; preds = %41
br label %158
48: ; preds = %38
%49 = load i32, i32* %12
%50 = icmp eq i32 %49, 2
br i1 %50, label %51, label %57
51: ; preds = %48
%52 = load i8*, i8** %11
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %51
br label %161
56: ; preds = %51
br label %157
57: ; preds = %48
%58 = load i32, i32* %12
%59 = icmp eq i32 %58, 3
br i1 %59, label %60, label %156
60: ; preds = %57
%61 = load i8*, i8** %11
%62 = call i32 @isPartitionName(i8* %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %60
br label %161
65: ; preds = %60
%66 = load i8*, i8** %3
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = load i8*, i8** %3
%70 = load i8*, i8** %11
%71 = load i8*, i8** %3
%72 = call i32 @strlen(i8* %71)
%73 = call i64 @strncmp(i8* %69, i8* %70, i32 %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %68
br label %161
76: ; preds = %68, %65
%77 = load i8*, i8** %11
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %78, 7
%80 = call i64 @malloc(i32 %79)
%81 = inttoptr i64 %80 to i8*
store i8* %81, i8** %8
%82 = load i8*, i8** %8
%83 = load i8*, i8** %11
%84 = call i32 @sprintf(i8* %82, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %83)
%85 = load i8**, i8*** %6
%86 = icmp ne i8** %85, null
br i1 %86, label %95, label %87
87: ; preds = %76
%88 = call i64 @malloc(i32 16)
%89 = inttoptr i64 %88 to i8**
store i8** %89, i8*** %6
%90 = load i8*, i8** %8
%91 = load i8**, i8*** %6
%92 = getelementptr inbounds i8*, i8** %91, i64 0
store i8* %90, i8** %92
%93 = load i8**, i8*** %6
%94 = getelementptr inbounds i8*, i8** %93, i64 1
store i8* null, i8** %94
br label %153
95: ; preds = %76
%96 = load i8**, i8*** %6
%97 = load i32, i32* %5
%98 = add nsw i32 %97, 2
%99 = sext i32 %98 to i64
%100 = mul i64 %99, 8
%101 = trunc i64 %100 to i32
%102 = call i64 @realloc(i8** %96, i32 %101)
%103 = inttoptr i64 %102 to i8**
store i8** %103, i8*** %6
store i32 0, i32* %13
br label %104
104: ; preds = %118, %95
%105 = load i32, i32* %13
%106 = load i32, i32* %5
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %121
108: ; preds = %104
%109 = load i8*, i8** %8
%110 = load i8**, i8*** %6
%111 = load i32, i32* %13
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8*, i8** %110, i64 %112
%114 = load i8*, i8** %113
%115 = call i64 @strcmp(i8* %109, i8* %114)
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %108
br label %121
118: ; preds = %108
%119 = load i32, i32* %13
%120 = add nsw i32 %119, 1
store i32 %120, i32* %13
br label %104
121: ; preds = %117, %104
%122 = load i32, i32* %13
%123 = load i32, i32* %5
%124 = icmp ne i32 %122, %123
br i1 %124, label %125, label %142
125: ; preds = %121
%126 = load i8**, i8*** %6
%127 = load i32, i32* %13
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8*, i8** %126, i64 %128
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8**, i8*** %6
%132 = load i32, i32* %13
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i8*, i8** %131, i64 %133
%135 = load i32, i32* %5
%136 = load i32, i32* %13
%137 = sub nsw i32 %135, %136
%138 = sext i32 %137 to i64
%139 = mul i64 %138, 8
%140 = trunc i64 %139 to i32
%141 = call i32 @memmove(i8** %130, i8** %134, i32 %140)
br label %142
142: ; preds = %125, %121
%143 = load i8*, i8** %8
%144 = load i8**, i8*** %6
%145 = load i32, i32* %13
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8*, i8** %144, i64 %146
store i8* %143, i8** %147
%148 = load i8**, i8*** %6
%149 = load i32, i32* %5
%150 = add nsw i32 %149, 1
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i8*, i8** %148, i64 %151
store i8* null, i8** %152
br label %153
153: ; preds = %142, %87
%154 = load i32, i32* %5
%155 = add nsw i32 %154, 1
store i32 %155, i32* %5
br label %161
156: ; preds = %57
br label %157
157: ; preds = %156, %56
br label %158
158: ; preds = %157, %47
%159 = load i32, i32* %12
%160 = add nsw i32 %159, 1
store i32 %160, i32* %12
br label %28
161: ; preds = %153, %75, %64, %55, %46, %32
br label %163
162: ; preds = %20
br label %164
163: ; preds = %161
br label %20
164: ; preds = %162
%165 = load i32*, i32** %4
%166 = call i32 @fclose(i32* %165)
%167 = load i8**, i8*** %6
store i8** %167, i8*** %2
br label %168
168: ; preds = %164, %17
%169 = load i8**, i8*** %2
ret i8** %169
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/partitions\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [51 x i8] c"getPartitionsList: could not open /proc/partitions\00"
@.str.3 = [3 x i8] c" \0A\00"
@.str.4 = [2 x i8] c"1\00"
@.str.5 = [8 x i8] c"/dev/%s\00"
define i8** @getPartitionsList(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = call i8* @fgets(i8* %7, i32 4096, i32* %4)
%9 = icmp eq i8* %8, null
br i1 %9, label %107, label %10
10: ; preds = %6
%11 = bitcast i8** %3 to i8*
%12 = icmp eq i8* %0, null
br label %15
13: ; preds = %1
%14 = tail call i32 @logMessage(i32 40, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
br label %110
15: ; preds = %10, %102
%16 = phi i32 [ 0, %10 ], [ %104, %102 ]
%17 = phi i8** [ null, %10 ], [ %103, %102 ]
store i8* %7, i8** %3
br label %18
18: ; preds = %15, %21
%19 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %102, label %21
21: ; preds = %18
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 0
br i1 %23, label %18, label %24
24: ; preds = %21
%25 = call i32 @isdigit(i8 signext %22)
%26 = icmp eq i32 %25, 0
br i1 %26, label %102, label %81
27: ; preds = %99
%28 = call i32 @isPartitionName(i8* %97)
%29 = icmp eq i32 %28, 0
br i1 %29, label %102, label %30
30: ; preds = %27
br i1 %12, label %35, label %31
31: ; preds = %30
%32 = call i32 @strlen(i8* %0)
%33 = call i64 @strncmp(i8* %0, i8* %97, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %102
35: ; preds = %31, %30
%36 = call i32 @strlen(i8* %97)
%37 = add nsw i32 %36, 7
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %97)
%41 = icmp eq i8** %17, null
br i1 %41, label %42, label %47
42: ; preds = %35
%43 = call i64 @malloc(i32 16)
%44 = inttoptr i64 %43 to i8**
store i8* %39, i8** %44
%45 = getelementptr inbounds i8*, i8** %44, i64 1
store i8* null, i8** %45
%46 = add nsw i32 %16, 1
br label %102
47: ; preds = %35
%48 = shl i32 %16, 3
%49 = add i32 %48, 16
%50 = call i64 @realloc(i8** %17, i32 %49)
%51 = inttoptr i64 %50 to i8**
%52 = icmp sgt i32 %16, 0
br i1 %52, label %53, label %66
53: ; preds = %47
%54 = zext i32 %16 to i64
br label %55
55: ; preds = %53, %61
%56 = phi i64 [ 0, %53 ], [ %62, %61 ]
%57 = getelementptr inbounds i8*, i8** %51, i64 %56
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %39, i8* %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %55
%62 = add nuw nsw i64 %56, 1
%63 = icmp eq i64 %62, %54
br i1 %63, label %66, label %55
64: ; preds = %55
%65 = trunc i64 %56 to i32
br label %66
66: ; preds = %61, %64, %47
%67 = phi i32 [ 0, %47 ], [ %65, %64 ], [ %16, %61 ]
%68 = icmp eq i32 %16, %67
%69 = zext i32 %67 to i64
br i1 %68, label %76, label %70
70: ; preds = %66
%71 = getelementptr inbounds i8*, i8** %51, i64 %69
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = sub nsw i32 %16, %67
%74 = shl i32 %73, 3
%75 = call i32 @memmove(i8** %72, i8** %71, i32 %74)
br label %76
76: ; preds = %66, %70
%77 = getelementptr inbounds i8*, i8** %51, i64 %69
store i8* %39, i8** %77
%78 = add nsw i32 %16, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %51, i64 %79
store i8* null, i8** %80
br label %102
81: ; preds = %24, %84
%82 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%83 = icmp eq i8* %82, null
br i1 %83, label %102, label %84
84: ; preds = %81
%85 = load i8, i8* %82
%86 = icmp eq i8 %85, 0
br i1 %86, label %81, label %87
87: ; preds = %84, %90
%88 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%89 = icmp eq i8* %88, null
br i1 %89, label %102, label %90
90: ; preds = %87
%91 = load i8, i8* %88
%92 = icmp eq i8 %91, 0
br i1 %92, label %87, label %93
93: ; preds = %90
%94 = call i64 @strcmp(i8* %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %102, label %96
96: ; preds = %93, %99
%97 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%98 = icmp eq i8* %97, null
br i1 %98, label %102, label %99
99: ; preds = %96
%100 = load i8, i8* %97
%101 = icmp eq i8 %100, 0
br i1 %101, label %96, label %27
102: ; preds = %18, %81, %87, %96, %24, %93, %42, %76, %27, %31
%103 = phi i8** [ %17, %31 ], [ %17, %27 ], [ %51, %76 ], [ %44, %42 ], [ %17, %93 ], [ %17, %24 ], [ %17, %96 ], [ %17, %87 ], [ %17, %81 ], [ %17, %18 ]
%104 = phi i32 [ %16, %31 ], [ %16, %27 ], [ %78, %76 ], [ %46, %42 ], [ %16, %93 ], [ %16, %24 ], [ %16, %96 ], [ %16, %87 ], [ %16, %81 ], [ %16, %18 ]
%105 = call i8* @fgets(i8* %7, i32 4096, i32* %4)
%106 = icmp eq i8* %105, null
br i1 %106, label %107, label %15
107: ; preds = %102, %6
%108 = phi i8** [ null, %6 ], [ %103, %102 ]
%109 = call i32 @fclose(i32* %4)
br label %110
110: ; preds = %107, %13
%111 = phi i8** [ %108, %107 ], [ null, %13 ]
ret i8** %111
}