#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*/ BLKFLSBUF;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int c, f, rc = 0;
  if (argc == 1) {
    fprintf(stderr,
            "Usage: %s /dev/rd/initrd "
            "[ /dev/rd/12 [ .. ] ]\n",
            argv[0]);
    return 1;
  }
  for (c = 1; c < argc; c++) {
    if ((f = open(argv[c], O_RDWR)) == -1) {
      fprintf(stderr, "freeramdisk: cannot open %s: %s\n", argv[c],
              strerror(errno));
      rc++;
    } else {
      ioctl(f, BLKFLSBUF);
      close(f);
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a1 <main+0x51>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x10c>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1256 <main+0x106>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    122a <main+0xda>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1243 <main+0xf3>
mov    -0x18(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    1248 <main+0xf8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x58>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x1,%edi
jne    1189 <main+0x39>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
jmp    122f <main+0xdf>
xor    %r15d,%r15d
cmp    $0x2,%edi
jl     122f <main+0xdf>
mov    %edi,%r13d
mov    $0x1,%r14d
mov    0x2e43(%rip),%rbx
xor    %r15d,%r15d
jmp    11d2 <main+0x82>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     122f <main+0xdf>
mov    (%r12,%r14,8),%rdi
mov    (%rbx),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
mov    0x2de7(%rip),%rax
mov    (%rax),%ebp
mov    %r15d,0x4(%rsp)
mov    %r13,%r15
mov    %rbx,%r13
mov    (%r12,%r14,8),%rbx
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %ebp,%edi
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdx
mov    %r13,%rbx
mov    %r15,%r13
mov    0x4(%rsp),%r15d
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r15d
jmp    11c9 <main+0x79>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"Usage: %s /dev/rd/initrd [ /dev/rd/12 [ .. ] ]\0A\00"
@O_RDWR = global i32 0
@.str.1 = [33 x i8] c"freeramdisk: cannot open %s: %s\0A\00"
@errno = global i32 0
@BLKFLSBUF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %55
17: ; preds = %2
store i32 1, i32* %6
br label %18
18: ; preds = %50, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %53
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDWR
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %7
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %43
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %39)
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %49
43: ; preds = %22
%44 = load i32, i32* %7
%45 = load i32, i32* @BLKFLSBUF
%46 = call i32 @ioctl(i32 %44, i32 %45)
%47 = load i32, i32* %7
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %43, %31
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %18
53: ; preds = %18
%54 = load i32, i32* %8
store i32 %54, i32* %3
br label %55
55: ; preds = %53, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"Usage: %s /dev/rd/initrd [ /dev/rd/12 [ .. ] ]\0A\00"
@O_RDWR = global i32 0
@.str.1 = [33 x i8] c"freeramdisk: cannot open %s: %s\0A\00"
@errno = global i32 0
@BLKFLSBUF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %35
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %35
12: ; preds = %6, %31
%13 = phi i64 [ 1, %6 ], [ %33, %31 ]
%14 = phi i32 [ 0, %6 ], [ %32, %31 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %13
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %15
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
%26 = add nsw i32 %14, 1
br label %31
27: ; preds = %12
%28 = load i32, i32* @BLKFLSBUF
%29 = tail call i32 @ioctl(i32 %18, i32 %28)
%30 = tail call i32 @close(i32 %18)
br label %31
31: ; preds = %20, %27
%32 = phi i32 [ %26, %20 ], [ %14, %27 ]
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, %7
br i1 %34, label %35, label %12
35: ; preds = %31, %4, %8
%36 = phi i32 [ 1, %8 ], [ 0, %4 ], [ %32, %31 ]
ret i32 %36
}