#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_WRONLY;
scalar_t__ dprintf(int, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  if (argc != 2) {
    fprintf(stderr, "bcache-register takes exactly one argument\n");
    return 1;
  }
  fd = open("/sys/fs/bcache/register", O_WRONLY);
  if (fd < 0) {
    perror("Error opening /sys/fs/bcache/register");
    fprintf(stderr, "The bcache kernel module must be loaded\n");
    return 1;
  }
  if (dprintf(fd, "%s\n", argv[1]) < 0) {
    fprintf(stderr, "Error registering %s with bcache: %m\n", argv[1]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1183 <main+0x43>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1227 <main+0xe7>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d4 <main+0x94>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1227 <main+0xe7>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe95(%rip),%rsi
call   1030 <dprintf@plt>
cmp    $0x0,%rax
jge    1220 <main+0xe0>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1227 <main+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1180 <main+0x40>
mov    %rsi,%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xee1(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11bb <main+0x7b>
mov    0x8(%rbx),%rdx
lea    0xf0e(%rip),%rsi
mov    %eax,%edi
call   1030 <dprintf@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1199 <main+0x59>
pop    %rbx
ret
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b4 <main+0x74>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xed2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
jmp    1190 <main+0x50>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"bcache-register takes exactly one argument\0A\00"
@.str.1 = [24 x i8] c"/sys/fs/bcache/register\00"
@O_WRONLY = global i32 0
@.str.2 = [38 x i8] c"Error opening /sys/fs/bcache/register\00"
@.str.3 = [41 x i8] c"The bcache kernel module must be loaded\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [38 x i8] c"Error registering %s with bcache: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %35
12: ; preds = %2
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %35
21: ; preds = %12
%22 = load i32, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @dprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %35
34: ; preds = %21
store i32 0, i32* %3
br label %35
35: ; preds = %34, %28, %17, %9
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"bcache-register takes exactly one argument\0A\00"
@.str.1 = [24 x i8] c"/sys/fs/bcache/register\00"
@O_WRONLY = global i32 0
@.str.2 = [38 x i8] c"Error opening /sys/fs/bcache/register\00"
@.str.3 = [41 x i8] c"The bcache kernel module must be loaded\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [38 x i8] c"Error registering %s with bcache: %m\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %24
7: ; preds = %2
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %24
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i64 @dprintf(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %16
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %15, %20, %11, %4
%25 = phi i32 [ 1, %4 ], [ 1, %11 ], [ 1, %20 ], [ 0, %15 ]
ret i32 %25
}