#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ strlen(char const *const);
scalar_t__ uint32WriteToFD(int, int /*<<< orphan*/ *);
scalar_t__ write_FD(int, char const *const, int /*<<< orphan*/);
size_t astringWriteToFD(int fd, const char *const *data) {
  size_t count = 0;
  uint32_t length = (*data == NULL) ? 0 : strlen(*data);
  count += uint32WriteToFD(fd, &length);
  count += write_FD(fd, *data, length);
  return count;
}


x86 assembly (clang, -O0):
<astringWriteToFD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    115f <astringWriteToFD+0x2f>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    116e <astringWriteToFD+0x3e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1050 <uint32WriteToFD@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write_FD@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astringWriteToFD>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
test   %rdi,%rdi
je     114c <astringWriteToFD+0x1c>
call   1040 <strlen@plt>
jmp    114e <astringWriteToFD+0x1e>
xor    %eax,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
call   1050 <uint32WriteToFD@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
mov    0xc(%rsp),%edx
mov    %ebp,%edi
call   1030 <write_FD@plt>
add    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @astringWriteToFD(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %15
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
%14 = call i32 @strlen(i8* %13)
br label %15
15: ; preds = %11, %10
%16 = phi i32 [ 0, %10 ], [ %14, %11 ]
store i32 %16, i32* %6
%17 = load i32, i32* %3
%18 = call i64 @uint32WriteToFD(i32 %17, i32* %6)
%19 = load i64, i64* %5
%20 = add i64 %19, %18
store i64 %20, i64* %5
%21 = load i32, i32* %3
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i32, i32* %6
%25 = call i64 @write_FD(i32 %21, i8* %23, i32 %24)
%26 = load i64, i64* %5
%27 = add i64 %26, %25
store i64 %27, i64* %5
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
define i64 @astringWriteToFD(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %5)
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ 0, %2 ]
store i32 %10, i32* %3
%11 = call i64 @uint32WriteToFD(i32 %0, i32* %3)
%12 = load i8*, i8** %1
%13 = load i32, i32* %3
%14 = call i64 @write_FD(i32 %0, i8* %12, i32 %13)
%15 = add i64 %14, %11
ret i64 %15
}