#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  if (argc != 3)
    goto usage;
  if ((fd = open(argv[2], O_WRONLY)) == -1)
    goto usage;
  write(fd, argv[1], strlen(argv[1]));
  close(fd);
  return 0;
usage:
  write(2, "write_proc <value> <path_to_proc_file>\n",
        strlen("write_proc <value> <path_to_proc_file>\n"));
  return 1;
}


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   $0x3,-0x8(%rbp)
je     1165 <main+0x25>
jmp    11cd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    118c <main+0x4c>
jmp    11cd <main+0x8d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <main+0xb3>
lea    0xe2c(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe19(%rip),%rsi
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1187 <main+0x47>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1187 <main+0x47>
mov    %eax,%ebp
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11aa <main+0x6a>
lea    0xe72(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [40 x i8] c"write_proc <value> <path_to_proc_file>\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, 3
br i1 %8, label %9, label %10
9: ; preds = %2
br label %30
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 2
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %10
br label %30
18: ; preds = %10
%19 = load i32, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %19, i8* %22, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
store i32 0, i32* %3
br label %33
30: ; preds = %17, %9
%31 = call i32 @strlen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @write(i32 2, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 1, i32* %3
br label %33
33: ; preds = %30, %18
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [40 x i8] c"write_proc <value> <path_to_proc_file>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = tail call i32 @write(i32 %8, i8* %12, i32 %13)
%15 = tail call i32 @close(i32 %8)
br label %19
16: ; preds = %4, %2
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %10
%20 = phi i32 [ 1, %16 ], [ 0, %10 ]
ret i32 %20
}