#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 int /*<<< orphan*/ str;

/* Variables and functions */
scalar_t__ EFAULT;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int write(int /*<<< orphan*/, char const *, int);
int test_misbehave() {
  const char str[] = "Hello world from a user program!\n";
  assert(write(STDOUT_FILENO, str, sizeof(str) - 1) == sizeof(str) - 1);
  assert(write(STDOUT_FILENO, (char *)0xDEADC0DE, 100) == -1);
  assert(errno == EFAULT);
  assert(write(STDOUT_FILENO, (char *)0x1EE7C0DE, 100) == -1);
  assert(errno == EFAULT);
  return 0;
}


x86 assembly (clang, -O0):
<test_misbehave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x22,%edx
call   1050 <memcpy@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x21,%edx
call   1030 <write@plt>
cltq
cmp    $0x21,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    $0xdeadc0de,%esi
mov    $0x64,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    $0x1ee7c0de,%esi
mov    $0x64,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_misbehave>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0xa,0x20(%rsp)
mov    0x2e9a(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
mov    $0x21,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x21,%eax
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%edi
mov    $0xdeadc0de,%esi
mov    $0x64,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e3d(%rip),%rbx
mov    (%rbx),%rax
mov    0x2e5b(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%edi
mov    $0x1ee7c0de,%esi
mov    $0x64,%edx
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    (%rbx),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_misbehave.str = [34 x i8] c"Hello world from a user program!\0A\00"
@STDOUT_FILENO = global i32 0
@errno = global i64 0
@EFAULT = global i64 0
define i32 @test_misbehave() {
%1 = alloca [34 x i8]
%2 = bitcast [34 x i8]* %1 to i8*
%3 = load i32, i32* @STDOUT_FILENO
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%5 = call i32 @write(i32 %3, i8* %4, i32 33)
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, 33
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* inttoptr (i64 3735929054 to i8*), i32 100)
%12 = icmp eq i32 %11, -1
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* @errno
%16 = load i64, i64* @EFAULT
%17 = icmp eq i64 %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @STDOUT_FILENO
%21 = call i32 @write(i32 %20, i8* inttoptr (i64 518504670 to i8*), i32 100)
%22 = icmp eq i32 %21, -1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i64, i64* @errno
%26 = load i64, i64* @EFAULT
%27 = icmp eq i64 %25, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@__const.test_misbehave.str = [34 x i8] c"Hello world from a user program!\0A\00"
@STDOUT_FILENO = global i32 0
@errno = global i64 0
@EFAULT = global i64 0
define i32 @test_misbehave() {
%1 = alloca [34 x i8]
%2 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @STDOUT_FILENO
%4 = call i32 @write(i32 %3, i8* %2, i32 33)
%5 = icmp eq i32 %4, 33
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i32, i32* @STDOUT_FILENO
%9 = tail call i32 @write(i32 %8, i8* inttoptr (i64 3735929054 to i8*), i32 100)
%10 = icmp eq i32 %9, -1
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load i64, i64* @errno
%14 = load i64, i64* @EFAULT
%15 = icmp eq i64 %13, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = load i32, i32* @STDOUT_FILENO
%19 = tail call i32 @write(i32 %18, i8* inttoptr (i64 518504670 to i8*), i32 100)
%20 = icmp eq i32 %19, -1
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = load i64, i64* @errno
%24 = load i64, i64* @EFAULT
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
ret i32 0
}