#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*/ UNLLog(int, char *, char const *);
int /*<<< orphan*/ _SC_ARG_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int /*<<< orphan*/);
scalar_t__ strnlen(char const *, int);
int sysconf(int /*<<< orphan*/);
void cmd_add(char **cmd_line, const char *cmd) {
  if ((int)strnlen(*cmd_line, sizeof(*cmd_line)) +
          (int)strnlen(cmd, sizeof(*cmd)) + 1 >
      sysconf(_SC_ARG_MAX)) {
    UNLLog(1, "Cannot add command '%s' (string too long).\n", cmd);
    exit(1);
  }
  strncat(*cmd_line, cmd, strlen(cmd));
}


x86 assembly (clang, -O0):
<cmd_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <strnlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jle    11da <cmd_add+0x7a>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe35(%rip),%rsi
call   1060 <UNLLog@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_add>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    (%rdi),%rdi
mov    $0x8,%esi
call   1040 <strnlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <strnlen@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    %eax,%ebx
jge    11c6 <cmd_add+0x66>
mov    (%r14),%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <strncat@plt>
lea    0xe33(%rip),%rsi
mov    $0x1,%edi
mov    %r12,%rdx
call   1060 <UNLLog@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@_SC_ARG_MAX = global i32 0
@.str = [44 x i8] c"Cannot add command '%s' (string too long).\0A\00"
define void @cmd_add(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%5 = load i8**, i8*** %3
%6 = load i8*, i8** %5
%7 = call i64 @strnlen(i8* %6, i32 8)
%8 = trunc i64 %7 to i32
%9 = load i8*, i8** %4
%10 = call i64 @strnlen(i8* %9, i32 1)
%11 = trunc i64 %10 to i32
%12 = add nsw i32 %8, %11
%13 = add nsw i32 %12, 1
%14 = load i32, i32* @_SC_ARG_MAX
%15 = call i32 @sysconf(i32 %14)
%16 = icmp sgt i32 %13, %15
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @UNLLog(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @strncat(i8* %23, i8* %24, i32 %26)
ret void
}

LLVM IR (-O2):
@_SC_ARG_MAX = global i32 0
@.str = [44 x i8] c"Cannot add command '%s' (string too long).\0A\00"
define void @cmd_add(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @strnlen(i8* %3, i32 8)
%5 = trunc i64 %4 to i32
%6 = tail call i64 @strnlen(i8* %1, i32 1)
%7 = trunc i64 %6 to i32
%8 = add nsw i32 %7, %5
%9 = load i32, i32* @_SC_ARG_MAX
%10 = tail call i32 @sysconf(i32 %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = tail call i32 @UNLLog(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %1)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %0
%17 = tail call i32 @strlen(i8* %1)
%18 = tail call i32 @strncat(i8* %16, i8* %1, i32 %17)
ret void
}