#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*/ uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ _ProtoBufSetLenDelim(int /*<<< orphan*/ *, size_t,
                                        char const *, size_t, size_t *);
int /*<<< orphan*/ _ProtoBufSetVarInt(int /*<<< orphan*/ *, size_t, int,
                                      size_t *);
size_t strlen(char const *);
void _ProtoBufSetString(uint8_t *buf, size_t bufLen, const char *str,
                        uint64_t key, size_t *off) {
  size_t strLen = (str) ? strlen(str) : 0;
  _ProtoBufSetVarInt(buf, bufLen, (key << 3) | 2, off);
  _ProtoBufSetLenDelim(buf, bufLen, str, strLen, off);
}


x86 assembly (clang, -O0):
<_ProtoBufSetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1168 <_ProtoBufSetString+0x38>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    1173 <_ProtoBufSetString+0x43>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    1173 <_ProtoBufSetString+0x43>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
shl    $0x3,%edx
or     $0x2,%edx
mov    -0x28(%rbp),%rcx
call   1030 <_ProtoBufSetVarInt@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1050 <_ProtoBufSetLenDelim@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ProtoBufSetString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r13d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
test   %rdx,%rdx
je     115c <_ProtoBufSetString+0x2c>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
jmp    115e <_ProtoBufSetString+0x2e>
xor    %ebp,%ebp
lea    0x2(,%r13,8),%edx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1030 <_ProtoBufSetVarInt@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_ProtoBufSetLenDelim@plt>

LLVM IR (-O0):
define void @_ProtoBufSetString(i32* %0, i64 %1, i8* %2, i32 %3, i64* %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64*
%11 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i64* %4, i64** %10
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = load i8*, i8** %8
%16 = call i64 @strlen(i8* %15)
br label %18
17: ; preds = %5
br label %18
18: ; preds = %17, %14
%19 = phi i64 [ %16, %14 ], [ 0, %17 ]
store i64 %19, i64* %11
%20 = load i32*, i32** %6
%21 = load i64, i64* %7
%22 = load i32, i32* %9
%23 = shl i32 %22, 3
%24 = or i32 %23, 2
%25 = load i64*, i64** %10
%26 = call i32 @_ProtoBufSetVarInt(i32* %20, i64 %21, i32 %24, i64* %25)
%27 = load i32*, i32** %6
%28 = load i64, i64* %7
%29 = load i8*, i8** %8
%30 = load i64, i64* %11
%31 = load i64*, i64** %10
%32 = call i32 @_ProtoBufSetLenDelim(i32* %27, i64 %28, i8* %29, i64 %30, i64* %31)
ret void
}

LLVM IR (-O2):
define void @_ProtoBufSetString(i32* %0, i64 %1, i8* %2, i32 %3, i64* %4) {
%6 = icmp eq i8* %2, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i64 @strlen(i8* %2)
br label %9
9: ; preds = %5, %7
%10 = phi i64 [ %8, %7 ], [ 0, %5 ]
%11 = shl i32 %3, 3
%12 = or i32 %11, 2
%13 = tail call i32 @_ProtoBufSetVarInt(i32* %0, i64 %1, i32 %12, i64* %4)
%14 = tail call i32 @_ProtoBufSetLenDelim(i32* %0, i64 %1, i8* %2, i64 %10, i64* %4)
ret void
}