#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ strlen(char *);
scalar_t__ write(int /*<<< orphan*/, char *, int);
void write_stdout(char text[]) {
  if (write(STDOUT_FILENO, text, strlen(text)) != strlen(text)) {
    write(STDERR_FILENO, "There was an error writing to standard out\n", 44);
    return;
  }
}


x86 assembly (clang, -O0):
<write_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
je     118e <write_stdout+0x6e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_stdout>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ec3(%rip),%rax
mov    (%rax),%ebp
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jne    1157 <write_stdout+0x37>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    $0x2c,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [44 x i8] c"There was an error writing to standard out\0A\00"
define void @write_stdout(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i32, i32* @STDOUT_FILENO
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = trunc i64 %6 to i32
%8 = call i64 @write(i32 %3, i8* %4, i32 %7)
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = icmp ne i64 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @STDERR_FILENO
%14 = call i64 @write(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 44)
br label %15
15: ; preds = %12, %1
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [44 x i8] c"There was an error writing to standard out\0A\00"
define void @write_stdout(i8* nocapture %0) {
%2 = load i32, i32* @STDOUT_FILENO
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = tail call i64 @write(i32 %2, i8* %0, i32 %4)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = icmp eq i64 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i64 @write(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 44)
br label %11
11: ; preds = %8, %1
ret void
}