#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ write(int, unsigned char *, int);
int main(void) {
  unsigned char buf[] = {103, 0, 0, 0, 0, 220};
  ssize_t written;
  int miscdev;
  miscdev = open("/dev/ecryptfs", O_WRONLY);
  if (miscdev < 0)
    return 1;
  written = write(miscdev, buf, 1073741824);
  close(miscdev);
  return written < 0 ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <main+0x51>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <main+0x83>
mov    -0x1c(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x40000000,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rdx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movw   $0xdc00,0x4(%rsp)
movl   $0x67,(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1180 <main+0x50>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x40000000,%edx
call   1030 <write@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <close@plt>
shr    $0x3e,%rbx
not    %ebx
and    $0x2,%ebx
jmp    1185 <main+0x55>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf = [6 x i8] c"g\00\00\00\00\DC"
@.str = [14 x i8] c"/dev/ecryptfs\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [6 x i8]* %2 to i8*
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %21
11: ; preds = %0
%12 = load i32, i32* %4
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%14 = call i64 @write(i32 %12, i8* %13, i32 1073741824)
store i64 %14, i64* %3
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i64, i64* %3
%18 = icmp slt i64 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 0, i32 2
store i32 %20, i32* %1
br label %21
21: ; preds = %11, %10
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@__const.main.buf = [6 x i8] c"g\00\00\00\00\DC"
@.str = [14 x i8] c"/dev/ecryptfs\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = call i64 @write(i32 %4, i8* %2, i32 1073741824)
%8 = tail call i32 @close(i32 %4)
%9 = lshr i64 %7, 62
%10 = trunc i64 %9 to i32
%11 = and i32 %10, 2
%12 = xor i32 %11, 2
br label %13
13: ; preds = %0, %6
%14 = phi i32 [ %12, %6 ], [ 1, %0 ]
ret i32 %14
}