#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ asprintf(char **, char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ createDevNode(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logMessage(int, char *, ...);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
scalar_t__ strncmp(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int createPartitionNodes() {
  DIR *d, *subd;
  int numfound = 0;
  struct dirent *dirp;
  struct dirent *subdirp;
  logMessage(10, "Creating device nodes...");
  d = opendir("/sys/block");
  if (!d) {
    logMessage(40, "Cannot read /sys/block. Device nodes will not be created "
                   "and driver discs may not work");
    return -1;
  }
  while ((dirp = readdir(d)) != NULL) {
    char *dname;
    if (!strcmp(dirp->d_name, "..") || !strcmp(dirp->d_name, "."))
      continue;
    logMessage(10, "Trying to create device nodes for %s.", dirp->d_name);
    if (asprintf(&dname, "/sys/block/%s/dev", dirp->d_name) <= 0) {
      logMessage(40, "Cannot allocate memory for device info (%s).",
                 dirp->d_name);
      continue;
    }
    if (!createDevNode(dname, dirp->d_name))
      numfound++;
    free(dname);
    if (asprintf(&dname, "/sys/block/%s", dirp->d_name) <= 0) {
      logMessage(40, "Cannot allocate memory for device subdirectory (%s).",
                 dirp->d_name);
      continue;
    }
    subd = opendir(dname);
    if (!subd) {
      logMessage(40,
                 "Cannot read /sys/block/%s. Partition nodes will not be "
                 "created and driver discs may not work",
                 dirp->d_name);
      free(dname);
      continue;
    }
    while ((subdirp = readdir(subd)) != NULL) {
      char *subdirname;
      if (strncmp(subdirp->d_name, dirp->d_name, strlen(dirp->d_name))) {
        continue;
      }
      logMessage(10, "Trying to create device nodes for %s.", subdirp->d_name);
      if (asprintf(&subdirname, "/sys/block/%s/%s/dev", dirp->d_name,
                   subdirp->d_name) <= 0) {
        logMessage(40, "Cannot allocate memory for device info (%s).",
                   subdirp->d_name);
        continue;
      }
      if (!createDevNode(subdirname, subdirp->d_name))
        numfound++;
      free(subdirname);
    }
    closedir(subd);
    free(dname);
  }
  closedir(d);
  return numfound;
}


x86 assembly (clang, -O0):
<createPartitionNodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x1c(%rbp)
mov    $0xa,%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
lea    0xe50(%rip),%rdi
call   1070 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fc <createPartitionNodes+0x5c>
mov    $0x28,%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145e <createPartitionNodes+0x2be>
jmp    1201 <createPartitionNodes+0x61>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     144f <createPartitionNodes+0x2af>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     124e <createPartitionNodes+0xae>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1253 <createPartitionNodes+0xb3>
jmp    1201 <createPartitionNodes+0x61>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    $0xa,%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   10c0 <asprintf@plt>
cmp    $0x0,%rax
jg     12ac <createPartitionNodes+0x10c>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    $0x28,%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
jmp    1201 <createPartitionNodes+0x61>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1050 <createDevNode@plt>
cmp    $0x0,%eax
jne    12cd <createPartitionNodes+0x12d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   10c0 <asprintf@plt>
cmp    $0x0,%rax
jg     1316 <createPartitionNodes+0x176>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    $0x28,%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
jmp    1201 <createPartitionNodes+0x61>
mov    -0x38(%rbp),%rdi
call   1070 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1355 <createPartitionNodes+0x1b5>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    $0x28,%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
jmp    1201 <createPartitionNodes+0x61>
jmp    135a <createPartitionNodes+0x1ba>
mov    -0x18(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1438 <createPartitionNodes+0x298>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1080 <strlen@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
je     13aa <createPartitionNodes+0x20a>
jmp    135a <createPartitionNodes+0x1ba>
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    $0xa,%edi
lea    0xcbf(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
lea    -0x40(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   10c0 <asprintf@plt>
cmp    $0x0,%rax
jg     1409 <createPartitionNodes+0x269>
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    $0x28,%edi
lea    0xcb6(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
jmp    135a <createPartitionNodes+0x1ba>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
call   1050 <createDevNode@plt>
cmp    $0x0,%eax
jne    142a <createPartitionNodes+0x28a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
jmp    135a <createPartitionNodes+0x1ba>
mov    -0x18(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
jmp    1201 <createPartitionNodes+0x61>
mov    -0x10(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createPartitionNodes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe4b(%rip),%rsi
xor    %r14d,%r14d
mov    $0xa,%edi
xor    %eax,%eax
call   1030 <logMessage@plt>
lea    0xe4e(%rip),%rdi
call   1070 <opendir@plt>
test   %rax,%rax
je     140b <createPartitionNodes+0x26b>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1401 <createPartitionNodes+0x261>
mov    %rax,%r12
lea    0xe1f(%rip),%rbx
lea    0xee0(%rip),%rbp
lea    0x8(%rsp),%r13
xor    %r14d,%r14d
mov    %r15,0x20(%rsp)
jmp    1238 <createPartitionNodes+0x98>
mov    (%r12),%edx
mov    $0x28,%edi
lea    0xe96(%rip),%rsi
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1401 <createPartitionNodes+0x261>
mov    (%r12),%edi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1224 <createPartitionNodes+0x84>
mov    (%r12),%edi
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1224 <createPartitionNodes+0x84>
mov    (%r12),%edx
mov    $0xa,%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    (%r12),%edx
mov    %r13,%rdi
lea    0xe24(%rip),%rsi
xor    %eax,%eax
call   10c0 <asprintf@plt>
test   %rax,%rax
jle    120d <createPartitionNodes+0x6d>
mov    0x8(%rsp),%rdi
mov    (%r12),%esi
call   1050 <createDevNode@plt>
cmp    $0x1,%eax
adc    $0x0,%r14d
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    (%r12),%edx
mov    %r13,%rdi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   10c0 <asprintf@plt>
test   %rax,%rax
jle    13bf <createPartitionNodes+0x21f>
mov    0x8(%rsp),%rdi
call   1070 <opendir@plt>
test   %rax,%rax
je     13d4 <createPartitionNodes+0x234>
mov    %rax,%rbp
mov    %r14d,0x14(%rsp)
jmp    1312 <createPartitionNodes+0x172>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x18(%rsp),%rdi
mov    (%r15),%esi
call   1050 <createDevNode@plt>
cmp    $0x1,%eax
adcl   $0x0,0x14(%rsp)
mov    0x18(%rsp),%rdi
call   1040 <free@plt>
mov    %rbx,%r13
mov    %rbp,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     139a <createPartitionNodes+0x1fa>
mov    %r13,%rbx
mov    (%r15),%r13d
mov    (%r12),%r14d
mov    %r14d,%edi
call   1080 <strlen@plt>
mov    %r13d,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    130f <createPartitionNodes+0x16f>
mov    (%r15),%edx
mov    $0xa,%edi
lea    0xd26(%rip),%rsi
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    (%r12),%edx
mov    (%r15),%ecx
lea    0x18(%rsp),%rdi
lea    0xe11(%rip),%rsi
xor    %eax,%eax
call   10c0 <asprintf@plt>
test   %rax,%rax
jg     12f0 <createPartitionNodes+0x150>
mov    (%r15),%edx
mov    $0x28,%edi
lea    0xd25(%rip),%rsi
xor    %eax,%eax
call   1030 <logMessage@plt>
jmp    130f <createPartitionNodes+0x16f>
mov    %rbp,%rdi
call   1090 <closedir@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    0x20(%rsp),%r15
mov    0x14(%rsp),%r14d
lea    0xc59(%rip),%rbx
jmp    13f5 <createPartitionNodes+0x255>
mov    (%r12),%edx
mov    $0x28,%edi
lea    0xd1f(%rip),%rsi
jmp    121d <createPartitionNodes+0x7d>
mov    (%r12),%edx
mov    $0x28,%edi
lea    0xd3f(%rip),%rsi
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
lea    0xce2(%rip),%rbp
jmp    1224 <createPartitionNodes+0x84>
mov    %r15,%rdi
call   1090 <closedir@plt>
jmp    1424 <createPartitionNodes+0x284>
lea    0xc12(%rip),%rsi
mov    $0x28,%edi
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [25 x i8] c"Creating device nodes...\00"
@.str.1 = [11 x i8] c"/sys/block\00"
@.str.2 = [87 x i8] c"Cannot read /sys/block. Device nodes will not be created and driver discs may not work\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [38 x i8] c"Trying to create device nodes for %s.\00"
@.str.6 = [18 x i8] c"/sys/block/%s/dev\00"
@.str.7 = [45 x i8] c"Cannot allocate memory for device info (%s).\00"
@.str.8 = [14 x i8] c"/sys/block/%s\00"
@.str.9 = [53 x i8] c"Cannot allocate memory for device subdirectory (%s).\00"
@.str.10 = [93 x i8] c"Cannot read /sys/block/%s. Partition nodes will not be created and driver discs may not work\00"
@.str.11 = [21 x i8] c"/sys/block/%s/%s/dev\00"
define i32 @createPartitionNodes() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca %struct.dirent*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %4
%9 = call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %142
15: ; preds = %0
br label %16
16: ; preds = %133, %76, %66, %43, %32, %15
%17 = load i32*, i32** %2
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %5
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %138
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %5
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strcmp(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load %struct.dirent*, %struct.dirent** %5
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @strcmp(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26, %20
br label %16
33: ; preds = %26
%34 = load %struct.dirent*, %struct.dirent** %5
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %36)
%38 = load %struct.dirent*, %struct.dirent** %5
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %40)
%42 = icmp sle i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %33
%44 = load %struct.dirent*, %struct.dirent** %5
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %46)
br label %16
48: ; preds = %33
%49 = load i8*, i8** %7
%50 = load %struct.dirent*, %struct.dirent** %5
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @createDevNode(i8* %49, i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %48
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %58
58: ; preds = %55, %48
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
%61 = load %struct.dirent*, %struct.dirent** %5
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %63)
%65 = icmp sle i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %58
%67 = load %struct.dirent*, %struct.dirent** %5
%68 = getelementptr inbounds %struct.dirent, %struct.dirent* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0), i32 %69)
br label %16
71: ; preds = %58
%72 = load i8*, i8** %7
%73 = call i32* @opendir(i8* %72)
store i32* %73, i32** %3
%74 = load i32*, i32** %3
%75 = icmp ne i32* %74, null
br i1 %75, label %83, label %76
76: ; preds = %71
%77 = load %struct.dirent*, %struct.dirent** %5
%78 = getelementptr inbounds %struct.dirent, %struct.dirent* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.10, i64 0, i64 0), i32 %79)
%81 = load i8*, i8** %7
%82 = call i32 @free(i8* %81)
br label %16
83: ; preds = %71
br label %84
84: ; preds = %130, %115, %101, %83
%85 = load i32*, i32** %3
%86 = call %struct.dirent* @readdir(i32* %85)
store %struct.dirent* %86, %struct.dirent** %6
%87 = icmp ne %struct.dirent* %86, null
br i1 %87, label %88, label %133
88: ; preds = %84
%89 = load %struct.dirent*, %struct.dirent** %6
%90 = getelementptr inbounds %struct.dirent, %struct.dirent* %89, i32 0, i32 0
%91 = load i32, i32* %90
%92 = load %struct.dirent*, %struct.dirent** %5
%93 = getelementptr inbounds %struct.dirent, %struct.dirent* %92, i32 0, i32 0
%94 = load i32, i32* %93
%95 = load %struct.dirent*, %struct.dirent** %5
%96 = getelementptr inbounds %struct.dirent, %struct.dirent* %95, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i32 @strlen(i32 %97)
%99 = call i64 @strncmp(i32 %91, i32 %94, i32 %98)
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %88
br label %84
102: ; preds = %88
%103 = load %struct.dirent*, %struct.dirent** %6
%104 = getelementptr inbounds %struct.dirent, %struct.dirent* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %105)
%107 = load %struct.dirent*, %struct.dirent** %5
%108 = getelementptr inbounds %struct.dirent, %struct.dirent* %107, i32 0, i32 0
%109 = load i32, i32* %108
%110 = load %struct.dirent*, %struct.dirent** %6
%111 = getelementptr inbounds %struct.dirent, %struct.dirent* %110, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %109, i32 %112)
%114 = icmp sle i64 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %102
%116 = load %struct.dirent*, %struct.dirent** %6
%117 = getelementptr inbounds %struct.dirent, %struct.dirent* %116, i32 0, i32 0
%118 = load i32, i32* %117
%119 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %118)
br label %84
120: ; preds = %102
%121 = load i8*, i8** %8
%122 = load %struct.dirent*, %struct.dirent** %6
%123 = getelementptr inbounds %struct.dirent, %struct.dirent* %122, i32 0, i32 0
%124 = load i32, i32* %123
%125 = call i32 @createDevNode(i8* %121, i32 %124)
%126 = icmp ne i32 %125, 0
br i1 %126, label %130, label %127
127: ; preds = %120
%128 = load i32, i32* %4
%129 = add nsw i32 %128, 1
store i32 %129, i32* %4
br label %130
130: ; preds = %127, %120
%131 = load i8*, i8** %8
%132 = call i32 @free(i8* %131)
br label %84
133: ; preds = %84
%134 = load i32*, i32** %3
%135 = call i32 @closedir(i32* %134)
%136 = load i8*, i8** %7
%137 = call i32 @free(i8* %136)
br label %16
138: ; preds = %16
%139 = load i32*, i32** %2
%140 = call i32 @closedir(i32* %139)
%141 = load i32, i32* %4
store i32 %141, i32* %1
br label %142
142: ; preds = %138, %13
%143 = load i32, i32* %1
ret i32 %143
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [25 x i8] c"Creating device nodes...\00"
@.str.1 = [11 x i8] c"/sys/block\00"
@.str.2 = [87 x i8] c"Cannot read /sys/block. Device nodes will not be created and driver discs may not work\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [38 x i8] c"Trying to create device nodes for %s.\00"
@.str.6 = [18 x i8] c"/sys/block/%s/dev\00"
@.str.7 = [45 x i8] c"Cannot allocate memory for device info (%s).\00"
@.str.8 = [14 x i8] c"/sys/block/%s\00"
@.str.9 = [53 x i8] c"Cannot allocate memory for device subdirectory (%s).\00"
@.str.10 = [93 x i8] c"Cannot read /sys/block/%s. Partition nodes will not be created and driver discs may not work\00"
@.str.11 = [21 x i8] c"/sys/block/%s/%s/dev\00"
define i32 @createPartitionNodes() {
%1 = alloca i8*
%2 = alloca i8*
%3 = tail call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %102, label %9
9: ; preds = %6
%10 = bitcast i8** %1 to i8*
%11 = bitcast i8** %2 to i8*
br label %14
12: ; preds = %0
%13 = tail call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0))
br label %105
14: ; preds = %9, %98
%15 = phi %struct.dirent* [ %7, %9 ], [ %100, %98 ]
%16 = phi i32 [ 0, %9 ], [ %99, %98 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @strcmp(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %98, label %21
21: ; preds = %14
%22 = load i32, i32* %17
%23 = call i32 @strcmp(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %98, label %25
25: ; preds = %21
%26 = load i32, i32* %17
%27 = call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %17
%29 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = icmp slt i64 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %17
%33 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %32)
br label %98
34: ; preds = %25
%35 = load i8*, i8** %1
%36 = load i32, i32* %17
%37 = call i32 @createDevNode(i8* %35, i32 %36)
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = add nsw i32 %16, %39
%41 = load i8*, i8** %1
%42 = call i32 @free(i8* %41)
%43 = load i32, i32* %17
%44 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = icmp slt i64 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %34
%47 = load i32, i32* %17
%48 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0), i32 %47)
br label %98
49: ; preds = %34
%50 = load i8*, i8** %1
%51 = call i32* @opendir(i8* %50)
%52 = icmp eq i32* %51, null
br i1 %52, label %56, label %53
53: ; preds = %49
%54 = call %struct.dirent* @readdir(i32* %51)
%55 = icmp eq %struct.dirent* %54, null
br i1 %55, label %93, label %61
56: ; preds = %49
%57 = load i32, i32* %17
%58 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.10, i64 0, i64 0), i32 %57)
%59 = load i8*, i8** %1
%60 = call i32 @free(i8* %59)
br label %98
61: ; preds = %53, %89
%62 = phi %struct.dirent* [ %91, %89 ], [ %54, %53 ]
%63 = phi i32 [ %90, %89 ], [ %40, %53 ]
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %62, i64 0, i32 0
%65 = load i32, i32* %64
%66 = load i32, i32* %17
%67 = call i32 @strlen(i32 %66)
%68 = call i64 @strncmp(i32 %65, i32 %66, i32 %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %89
70: ; preds = %61
%71 = load i32, i32* %64
%72 = call i32 (i32, i8*, ...) @logMessage(i32 10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %17
%74 = load i32, i32* %64
%75 = call i64 (i8**, i8*, i32, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %73, i32 %74)
%76 = icmp slt i64 %75, 1
br i1 %76, label %77, label %80
77: ; preds = %70
%78 = load i32, i32* %64
%79 = call i32 (i32, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %78)
br label %89
80: ; preds = %70
%81 = load i8*, i8** %2
%82 = load i32, i32* %64
%83 = call i32 @createDevNode(i8* %81, i32 %82)
%84 = icmp eq i32 %83, 0
%85 = zext i1 %84 to i32
%86 = add nsw i32 %63, %85
%87 = load i8*, i8** %2
%88 = call i32 @free(i8* %87)
br label %89
89: ; preds = %61, %80, %77
%90 = phi i32 [ %63, %77 ], [ %86, %80 ], [ %63, %61 ]
%91 = call %struct.dirent* @readdir(i32* %51)
%92 = icmp eq %struct.dirent* %91, null
br i1 %92, label %93, label %61
93: ; preds = %89, %53
%94 = phi i32 [ %40, %53 ], [ %90, %89 ]
%95 = call i32 @closedir(i32* %51)
%96 = load i8*, i8** %1
%97 = call i32 @free(i8* %96)
br label %98
98: ; preds = %14, %21, %93, %56, %46, %31
%99 = phi i32 [ %16, %31 ], [ %40, %46 ], [ %94, %93 ], [ %40, %56 ], [ %16, %21 ], [ %16, %14 ]
%100 = call %struct.dirent* @readdir(i32* %4)
%101 = icmp eq %struct.dirent* %100, null
br i1 %101, label %102, label %14
102: ; preds = %98, %6
%103 = phi i32 [ 0, %6 ], [ %99, %98 ]
%104 = call i32 @closedir(i32* %4)
br label %105
105: ; preds = %102, %12
%106 = phi i32 [ %103, %102 ], [ -1, %12 ]
ret i32 %106
}