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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ _IO(int, int);
int /*<<< orphan*/ dasd_close_device(int);
int dasd_open_device(char const *, int /*<<< orphan*/);
int errno;
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int dasd_reread_partition_table(const char *device, int ntries) {
  int i, fd, err = 0;
  fd = dasd_open_device(device, O_RDONLY);
  for (i = 0; i < ntries; i++) {
    if (ioctl(fd, _IO(0x12, 95), NULL) != 0) {
      err = errno;
      sleep(1);
    } else {
      err = 0;
      break;
    }
  }
  dasd_close_device(fd);
  return err;
}


x86 assembly (clang, -O0):
<dasd_reread_partition_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <dasd_open_device@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f5 <dasd_reread_partition_table+0xa5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x12,%edi
mov    $0x5f,%esi
call   1030 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11d6 <dasd_reread_partition_table+0x86>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11e2 <dasd_reread_partition_table+0x92>
movl   $0x0,-0x18(%rbp)
jmp    11f5 <dasd_reread_partition_table+0xa5>
jmp    11e7 <dasd_reread_partition_table+0x97>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1182 <dasd_reread_partition_table+0x32>
mov    -0x14(%rbp),%edi
call   1040 <dasd_close_device@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dasd_reread_partition_table>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1060 <dasd_open_device@plt>
mov    %eax,%r14d
test   %ebx,%ebx
jle    11b6 <dasd_reread_partition_table+0x66>
mov    0x2e63(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x12,%edi
mov    $0x5f,%esi
call   1030 <_IO@plt>
xor    %ebp,%ebp
mov    %r14d,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
je     11b8 <dasd_reread_partition_table+0x68>
mov    (%r15),%ebp
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0xffffffff,%ebx
jne    1180 <dasd_reread_partition_table+0x30>
jmp    11b8 <dasd_reread_partition_table+0x68>
xor    %ebp,%ebp
mov    %r14d,%edi
call   1040 <dasd_close_device@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @dasd_reread_partition_table(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @dasd_open_device(i8* %8, i32 %9)
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i32, i32* %6
%17 = call i32 @_IO(i32 18, i32 95)
%18 = call i64 @ioctl(i32 %16, i32 %17, i32* null)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* @errno
store i32 %21, i32* %7
%22 = call i32 @sleep(i32 1)
br label %24
23: ; preds = %15
store i32 0, i32* %7
br label %28
24: ; preds = %20
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %11
28: ; preds = %23, %11
%29 = load i32, i32* %6
%30 = call i32 @dasd_close_device(i32 %29)
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @dasd_reread_partition_table(i8* %0, i32 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @dasd_open_device(i8* %0, i32 %3)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %2, %11
%7 = phi i32 [ %14, %11 ], [ 0, %2 ]
%8 = tail call i32 @_IO(i32 18, i32 95)
%9 = tail call i64 @ioctl(i32 %4, i32 %8, i32* null)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = load i32, i32* @errno
%13 = tail call i32 @sleep(i32 1)
%14 = add nuw nsw i32 %7, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %6
16: ; preds = %11, %6, %2
%17 = phi i32 [ 0, %2 ], [ 0, %6 ], [ %12, %11 ]
%18 = tail call i32 @dasd_close_device(i32 %4)
ret i32 %17
}