#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 */
unsigned int atoi(char const *);
int /*<<< orphan*/ bmount(char const *);
int /*<<< orphan*/ bumount();
int mi_write(char const *, char const *, unsigned int, int const);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int strlen(char const *);
int main(int argc, char const *argv[]) {
  if (argc != 5) {
    puts("Uso: mi_escribir <nombre_dispositivo> <pathname> <\"$(cat "
         "fichero)\"> <offset> ");
    return -1;
  }
  unsigned int offset = atoi(argv[4]);
  const char *buffer = argv[3];
  const char *camino = argv[2];
  const int len = strlen(buffer);
  bmount(argv[1]);
  int resultado = mi_write(camino, buffer, offset, len);
  if (resultado < 0)
    return resultado;
  printf("%d bytes escritos.\n", resultado);
  bumount();
  return 0;
}


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)
cmpl   $0x5,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <bmount@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1040 <mi_write@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1214 <main+0xa4>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1231 <main+0xc1>
mov    -0x30(%rbp),%esi
lea    0xe30(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <bumount@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x5,%edi
jne    11d8 <main+0x68>
mov    %rsi,%rbx
mov    0x20(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%r15
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    0x8(%rbx),%rdi
call   1080 <bmount@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
call   1040 <mi_write@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11e9 <main+0x79>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <bumount@plt>
jmp    11e9 <main+0x79>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [78 x i8] c"Uso: mi_escribir <nombre_dispositivo> <pathname> <\22$(cat fichero)\22> <offset> \00"
@.str.1 = [20 x i8] c"%d bytes escritos.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %45
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 4
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
store i8* %22, i8** %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %8
%26 = load i8*, i8** %7
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %9
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @bmount(i8* %30)
%32 = load i8*, i8** %8
%33 = load i8*, i8** %7
%34 = load i32, i32* %6
%35 = load i32, i32* %9
%36 = call i32 @mi_write(i8* %32, i8* %33, i32 %34, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %15
%40 = load i32, i32* %10
store i32 %40, i32* %3
br label %45
41: ; preds = %15
%42 = load i32, i32* %10
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 (...) @bumount()
store i32 0, i32* %3
br label %45
45: ; preds = %41, %39, %13
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [78 x i8] c"Uso: mi_escribir <nombre_dispositivo> <pathname> <\22$(cat fichero)\22> <offset> \00"
@.str.1 = [20 x i8] c"%d bytes escritos.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
br label %23
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 4
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %11)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @bmount(i8* %16)
%18 = tail call i32 @mi_write(i8* %13, i8* %11, i32 %9, i32 %14)
%19 = icmp slt i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %6
%21 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%22 = tail call i32 (...) @bumount()
br label %23
23: ; preds = %20, %6, %4
%24 = phi i32 [ -1, %4 ], [ 0, %20 ], [ %18, %6 ]
ret i32 %24
}