#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*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int nano_main(int argc, char *argv[]) {
  printf("nano\n");
  if (argc != 3) {
    printf("nano: wrong number of parameters\n");
    return -1;
  }
  char *path = argv[1];
  char *text = argv[2];
  int filedes = open(path, 0x0002 | 0x0200);
  write(filedes, text, strlen(text));
  close(filedes);
  return 0;
}


x86 assembly (clang, -O0):
<nano_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     118d <nano_main+0x3d>
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <nano_main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x202,%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nano_main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%ebp
jne    119c <nano_main+0x4c>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rbx
mov    $0x202,%esi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    11ad <nano_main+0x5d>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"nano\0A\00"
@.str.1 = [34 x i8] c"nano: wrong number of parameters\0A\00"
define i32 @nano_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = call i32 @open(i8* %21, i32 514)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i8*, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = load i32, i32* %8
%29 = call i32 @close(i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %14, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@str = [5 x i8] c"nano\00"
@str.2 = [33 x i8] c"nano: wrong number of parameters\00"
define i32 @nano_main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.2, i64 0, i64 0))
br label %16
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @open(i8* %9, i32 514)
%13 = tail call i32 @strlen(i8* %11)
%14 = tail call i32 @write(i32 %12, i8* %11, i32 %13)
%15 = tail call i32 @close(i32 %12)
br label %16
16: ; preds = %7, %5
%17 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %17
}