#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*/ mntpath;
typedef int /*<<< orphan*/ devpath;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ MS_RDONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ mount(char *, char *, char const *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *, char *, char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strerror(int /*<<< orphan*/);
int mount_device(const char *device, const char *fstype) {
  char mntpath[100], devpath[100];
  snprintf(mntpath, sizeof(mntpath), "/tmp/mnt/%s", device);
  snprintf(devpath, sizeof(devpath), "/dev/%s", device);
  if (access(mntpath, F_OK) == 0) {
    return 1;
  }
  if (mount(devpath, mntpath, fstype, MS_RDONLY, "") != 0) {
    printf("Failed mounting %s at %s (type %s): %s\n", devpath, mntpath, fstype,
           strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<mount_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x64,%esi
lea    0xe89(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x64,%esi
lea    0xe79(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    11c0 <mount_device+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1257 <mount_device+0x107>
lea    -0xf0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x2e12(%rip),%rax
mov    (%rax),%ecx
lea    0xe5c(%rip),%r8
call   1030 <mount@plt>
cmp    $0x0,%rax
je     1250 <mount_device+0x100>
lea    -0xf0(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x108(%rbp),%rsi
mov    -0x100(%rbp),%rdx
mov    -0xf8(%rbp),%rcx
mov    %rax,%r8
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1257 <mount_device+0x107>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_device>:
push   %rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe98(%rip),%rdx
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rbp,%rcx
call   1050 <snprintf@plt>
lea    0xe88(%rip),%rdx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rbp,%rcx
call   1050 <snprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11fe <mount_device+0xae>
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
lea    0xe7c(%rip),%r8
mov    %rsp,%rdi
lea    0x70(%rsp),%rsi
mov    %r14,%rdx
call   1030 <mount@plt>
test   %rax,%rax
je     11fe <mount_device+0xae>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe2b(%rip),%rdi
mov    %rsp,%rsi
lea    0x70(%rsp),%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/mnt/%s\00"
@.str.1 = [8 x i8] c"/dev/%s\00"
@F_OK = global i32 0
@MS_RDONLY = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [40 x i8] c"Failed mounting %s at %s (type %s): %s\0A\00"
@errno = global i32 0
define i32 @mount_device(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @snprintf(i8* %11, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = load i32, i32* @F_OK
%16 = call i64 @access(i8* %14, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %3
br label %34
19: ; preds = %2
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i32, i32* @MS_RDONLY
%24 = call i64 @mount(i8* %20, i8* %21, i8* %22, i32 %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %27, i8* %28, i8* %29, i8* %31)
store i32 0, i32* %3
br label %34
33: ; preds = %19
store i32 1, i32* %3
br label %34
34: ; preds = %33, %26, %18
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/mnt/%s\00"
@.str.1 = [8 x i8] c"/dev/%s\00"
@F_OK = global i32 0
@MS_RDONLY = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [40 x i8] c"Failed mounting %s at %s (type %s): %s\0A\00"
@errno = global i32 0
define i32 @mount_device(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @snprintf(i8* %6, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @F_OK
%10 = call i64 @access(i8* %5, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i32, i32* @MS_RDONLY
%14 = call i64 @mount(i8* %6, i8* %5, i8* %1, i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %5, i8* %1, i8* %18)
br label %20
20: ; preds = %12, %2, %16
%21 = phi i32 [ 0, %16 ], [ 1, %2 ], [ 1, %12 ]
ret i32 %21
}