#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 hddown(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);
  return closedir(blk);
}


x86 assembly (clang, -O0):
<hddown>:
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 <hddown+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <hddown+0x6b>
jmp    1173 <hddown+0x33>
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <list_disks@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     119f <hddown+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <do_standby_disk@plt>
jmp    1173 <hddown+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):
<hddown>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1196 <hddown+0x56>
mov    %rax,%rbx
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1060 <list_disks@plt>
test   %rax,%rax
je     118c <hddown+0x4c>
lea    0x4(%rsp),%r14
nop
mov    0x4(%rsp),%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 <hddown+0x30>
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    119b <hddown+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/sys/block\00"
define i32 @hddown() {
%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 %20
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 %17
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %2
%16 = call i32 @do_standby_disk(i8* %14, i32 %15)
br label %9
17: ; preds = %9
%18 = load i32*, i32** %4
%19 = call i32 @closedir(i32* %18)
store i32 %19, i32* %1
br label %20
20: ; preds = %17, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [11 x i8] c"/sys/block\00"
define i32 @hddown() {
%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 %16, label %5
5: ; preds = %0
%6 = call i8* @list_disks(i32* %3, i32* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5, %8
%9 = phi i8* [ %12, %8 ], [ %6, %5 ]
%10 = load i32, i32* %1
%11 = call i32 @do_standby_disk(i8* %9, i32 %10)
%12 = call i8* @list_disks(i32* %3, i32* %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8, %5
%15 = call i32 @closedir(i32* %3)
br label %16
16: ; preds = %0, %14
%17 = phi i32 [ %15, %14 ], [ -1, %0 ]
ret i32 %17
}