#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*/ DIR;

/* Variables and functions */
int closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_standby_disk(char *, unsigned int);
char *list_disks(int /*<<< orphan*/ *, unsigned int *);
int /*<<< orphan*/ *opendir(char *);
int hdflush(void) {
  unsigned int flags;
  char *disk;
  DIR *blk;
  if ((blk = opendir("/sys/block")) == (DIR *)0)
    return -1;
  while ((disk = list_disks(blk, &flags)))
    do_standby_disk(disk, (flags | 0x00000020));
  return closedir(blk);
}


x86 assembly (clang, -O0):
<hdflush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116e <hdflush+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <hdflush+0x6e>
jmp    1173 <hdflush+0x33>
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <list_disks@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11a2 <hdflush+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
or     $0x20,%esi
call   1050 <do_standby_disk@plt>
jmp    1173 <hdflush+0x33>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdflush>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1199 <hdflush+0x59>
mov    %rax,%rbx
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1060 <list_disks@plt>
test   %rax,%rax
je     118f <hdflush+0x4f>
lea    0x4(%rsp),%r14
nop
mov    0x4(%rsp),%esi
or     $0x20,%esi
mov    %rax,%rdi
call   1050 <do_standby_disk@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <list_disks@plt>
test   %rax,%rax
jne    1170 <hdflush+0x30>
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    119e <hdflush+0x5e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/sys/block\00"
define i32 @hdflush() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %21
8: ; preds = %0
br label %9
9: ; preds = %13, %8
%10 = load i32*, i32** %4
%11 = call i8* @list_disks(i32* %10, i32* %2)
store i8* %11, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %2
%16 = or i32 %15, 32
%17 = call i32 @do_standby_disk(i8* %14, i32 %16)
br label %9
18: ; preds = %9
%19 = load i32*, i32** %4
%20 = call i32 @closedir(i32* %19)
store i32 %20, i32* %1
br label %21
21: ; preds = %18, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [11 x i8] c"/sys/block\00"
define i32 @hdflush() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = call i8* @list_disks(i32* %3, i32* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %5, %8
%9 = phi i8* [ %13, %8 ], [ %6, %5 ]
%10 = load i32, i32* %1
%11 = or i32 %10, 32
%12 = call i32 @do_standby_disk(i8* %9, i32 %11)
%13 = call i8* @list_disks(i32* %3, i32* %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %8
15: ; preds = %8, %5
%16 = call i32 @closedir(i32* %3)
br label %17
17: ; preds = %0, %15
%18 = phi i32 [ %16, %15 ], [ -1, %0 ]
ret i32 %18
}