#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 scalar_t__ uint64_t;

/* Variables and functions */
scalar_t__ malloc(scalar_t__ const);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ const strlen(char const *);
char *ut_build_nm_cmd(char const *filename) {
  uint64_t const filename_len_limit = 1024;
  char const *cmd_base = "nm ";
  if (strlen(filename) > filename_len_limit) {
    return (NULL);
  }
  char *cmd = (char *)malloc(strlen(cmd_base) + strlen(filename) + 1);
  strcpy(cmd, cmd_base);
  strcat(cmd, filename);
  return (cmd);
}


x86 assembly (clang, -O0):
<ut_build_nm_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x400,-0x18(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x400,%rax
jle    1181 <ut_build_nm_cmd+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11cd <ut_build_nm_cmd+0x8d>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_build_nm_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x400,%rax
jle    1158 <ut_build_nm_cmd+0x18>
xor    %ebx,%ebx
jmp    1181 <ut_build_nm_cmd+0x41>
add    $0x4,%rax
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"nm \00"
define i8* @ut_build_nm_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 1024, i64* %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = icmp sgt i64 %8, 1024
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %27
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = add nsw i64 %16, 1
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %6
store i8* %26, i8** %2
br label %27
27: ; preds = %11, %10
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"nm \00"
define i8* @ut_build_nm_cmd(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp sgt i64 %2, 1024
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = add nsw i64 %2, 4
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %7, i8* %0)
br label %10
10: ; preds = %1, %4
%11 = phi i8* [ %7, %4 ], [ null, %1 ]
ret i8* %11
}