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

/* Variables and functions */
int /*<<< orphan*/ errExit(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int write(int, char *, int);
void writeStuff(int fd, char outBuf[]) {
  ssize_t writtenBytes = write(fd, outBuf, strlen(outBuf));
  if (writtenBytes == -1) {
    printf("Error writing %s\n", outBuf);
    errExit("Writing");
  } else if (writtenBytes != strlen(outBuf))
    printf("Warning: %ld written out of %ld\n", (long)writtenBytes,
           (long)strlen(outBuf));
}


x86 assembly (clang, -O0):
<writeStuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a4 <writeStuff+0x64>
mov    -0x10(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe78(%rip),%rdi
call   1040 <errExit@plt>
jmp    11eb <writeStuff+0xab>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
je     11e6 <writeStuff+0xa6>
movslq -0x14(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rsi
movslq %eax,%rdx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11eb <writeStuff+0xab>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeStuff>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1176 <writeStuff+0x36>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebp
jne    1199 <writeStuff+0x59>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe84(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <errExit@plt>
movslq %ebp,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdx
lea    0xe6c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Error writing %s\0A\00"
@.str.1 = [8 x i8] c"Writing\00"
@.str.2 = [33 x i8] c"Warning: %ld written out of %ld\0A\00"
define void @writeStuff(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = load i8*, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @write(i32 %6, i8* %7, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @errExit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %30
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 %24, i64 %27)
br label %29
29: ; preds = %22, %17
br label %30
30: ; preds = %29, %13
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Error writing %s\0A\00"
@.str.1 = [8 x i8] c"Writing\00"
@.str.2 = [33 x i8] c"Warning: %ld written out of %ld\0A\00"
define void @writeStuff(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = tail call i32 @errExit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %17
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp eq i32 %4, %10
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = sext i32 %4 to i64
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i64 %13, i64 %15)
br label %17
17: ; preds = %9, %12, %6
ret void
}