#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);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int i = 11;
  int fd = open("/dev/null", O_WRONLY);
  char *buf = malloc(sizeof(char) * 6);
  char c = buf[-1];
  char *x = buf + (long)buf;
  char *y = (char *)((long)buf * i);
  write(fd, buf + 3, 5);
  close(fd);
  return x - y + c;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xb,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x3,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
movsbq -0x19(%rbp),%rcx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    $0x6,%edi
call   1050 <malloc@plt>
imul   $0xfffffff5,%eax,%ebp
add    %eax,%ebp
add    %eax,%ebp
lea    0x3(%rax),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
store i32 11, i32* %2
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = call i8* @malloc(i32 6)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8* %17, i8** %6
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %18 to i64
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = mul nsw i64 %19, %21
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %7
%24 = load i32, i32* %3
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = call i32 @write(i32 %24, i8* %26, i32 5)
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = load i8, i8* %5
%36 = sext i8 %35 to i64
%37 = add nsw i64 %34, %36
%38 = trunc i64 %37 to i32
ret i32 %38
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%4 = ptrtoint i8* %3 to i64
%5 = getelementptr inbounds i8, i8* %3, i64 %4
%6 = mul i64 %4, -11
%7 = getelementptr inbounds i8, i8* %3, i64 3
%8 = tail call i32 @write(i32 %2, i8* %7, i32 5)
%9 = tail call i32 @close(i32 %2)
%10 = ptrtoint i8* %5 to i64
%11 = add i64 %6, %10
%12 = trunc i64 %11 to i32
ret i32 %12
}