#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;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  int error;
  char buffer[80];
  if (argc != 2) {
    fprintf(stderr, "ERROR ARGUMENTS: Invalid number of arguments \n");
    return -1;
  }
  sprintf(buffer, "%s", argv[1]);
  fd = open("/dev/devDummy", O_WRONLY);
  if (fd < 0) {
    error = errno;
    fprintf(stderr, "ERROR OPEN: %s\n", strerror(error));
    return error;
  }
  if (write(fd, buffer, strlen(buffer)) <= 0) {
    error = errno;
    fprintf(stderr, "ERROR WRITE: %s\n", strerror(error));
    return error;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <main+0x148>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe66(%rip),%rsi
call   1080 <sprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    122f <main+0xbf>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b8 <main+0x148>
mov    -0x14(%rbp),%eax
mov    %eax,-0x84(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jg     12a9 <main+0x139>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    -0x18(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b8 <main+0x148>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%edi
jne    11c9 <main+0x59>
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11e7 <main+0x77>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jle    1209 <main+0x99>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
jmp    1235 <main+0xc5>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1235 <main+0xc5>
mov    0x2dea(%rip),%rax
mov    (%rax),%ebx
mov    0x2de9(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe36(%rip),%rsi
jmp    1229 <main+0xb9>
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe24(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"ERROR ARGUMENTS: Invalid number of arguments \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"/dev/devDummy\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.3 = [16 x i8] c"ERROR OPEN: %s\0A\00"
@.str.4 = [17 x i8] c"ERROR WRITE: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
14: ; preds = %2
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %14
%25 = load i32, i32* @errno
store i32 %25, i32* %7
%26 = load i32, i32* @stderr
%27 = load i32, i32* %7
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %48
31: ; preds = %14
%32 = load i32, i32* %6
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = call i64 @write(i32 %32, i8* %33, i32 %35)
%37 = icmp sle i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %31
%39 = load i32, i32* @errno
store i32 %39, i32* %7
%40 = load i32, i32* @stderr
%41 = load i32, i32* %7
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %7
store i32 %44, i32* %3
br label %48
45: ; preds = %31
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %38, %24, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"ERROR ARGUMENTS: Invalid number of arguments \0A\00"
@.str.2 = [14 x i8] c"/dev/devDummy\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.3 = [16 x i8] c"ERROR OPEN: %s\0A\00"
@.str.4 = [17 x i8] c"ERROR WRITE: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %32
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %11)
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i32, i32* @errno
%18 = load i32, i32* @stderr
%19 = call i8* @strerror(i32 %17)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %32
21: ; preds = %9
%22 = call i32 @strlen(i8* %4)
%23 = call i64 @write(i32 %14, i8* %4, i32 %22)
%24 = icmp slt i64 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* @errno
%27 = load i32, i32* @stderr
%28 = call i8* @strerror(i32 %26)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %32
30: ; preds = %21
%31 = call i32 @close(i32 %14)
br label %32
32: ; preds = %30, %25, %16, %6
%33 = phi i32 [ -1, %6 ], [ %17, %16 ], [ %26, %25 ], [ 0, %30 ]
ret i32 %33
}