#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*/ exit(int);
int /*<<< orphan*/ fh_log(char *, int, int /*<<< orphan*/ *, char *, char *);
char *fh_log_fmt(char *, char *, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int strlen(char const *);
char *fh_util_thread_name(const char *base, const char *proc) {
  int string_chars;
  char *thread_name = NULL;
  string_chars = strlen(proc) + strlen(base) + 1;
  thread_name = (char *)malloc((string_chars + 1) * sizeof(char));
  do {
    int nok = !(thread_name != NULL);
    if (nok) {
      char *_msg =
          fh_log_fmt("assertion '%s' failed at %s:%d", "thread_name != NULL",
                     "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/csinitiative/fhce/refs/"
                     "heads/master/common/fh_util.c",
                     144);
      fh_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/csinitiative/fhce/refs/heads/master/"
             "common/fh_util.c",
             144, NULL, "ERR", _msg);
      exit(1);
    }
  } while (0);
  sprintf(thread_name, "%s_%s", base, proc);
  return thread_name;
}


x86 assembly (clang, -O0):
<fh_util_thread_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     121a <fh_util_thread_name+0xba>
lea    0xe2c(%rip),%rdi
lea    0xe44(%rip),%rsi
lea    0xe51(%rip),%rdx
mov    $0x90,%ecx
call   1060 <fh_log_fmt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%r8
lea    0xe38(%rip),%rdi
mov    $0x90,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xeb7(%rip),%rcx
call   1040 <fh_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121f <fh_util_thread_name+0xbf>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe94(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fh_util_thread_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ae <fh_util_thread_name+0x4e>
mov    %rax,%rbx
lea    0xf2f(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe4b(%rip),%rdi
lea    0xe63(%rip),%rsi
lea    0xe70(%rip),%rbx
mov    %rbx,%rdx
mov    $0x90,%ecx
call   1060 <fh_log_fmt@plt>
lea    0xeeb(%rip),%rcx
mov    %rbx,%rdi
mov    $0x90,%esi
xor    %edx,%edx
mov    %rax,%r8
call   1040 <fh_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"assertion '%s' failed at %s:%d\00"
@.str.1 = [20 x i8] c"thread_name != NULL\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/csinitiative/fhce/refs/heads/master/common/fh_util.c\00"
@.str.3 = [4 x i8] c"ERR\00"
@.str.4 = [6 x i8] c"%s_%s\00"
define i8* @fh_util_thread_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
br label %22
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = call i8* @fh_log_fmt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 144)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = call i32 @fh_log(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 144, i32* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %22
br label %35
35: ; preds = %34
%36 = load i8*, i8** %6
%37 = load i8*, i8** %3
%38 = load i8*, i8** %4
%39 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %6
ret i8* %40
}

LLVM IR (-O2):
@.str = [31 x i8] c"assertion '%s' failed at %s:%d\00"
@.str.1 = [20 x i8] c"thread_name != NULL\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/csinitiative/fhce/refs/heads/master/common/fh_util.c\00"
@.str.3 = [4 x i8] c"ERR\00"
@.str.4 = [6 x i8] c"%s_%s\00"
define i8* @fh_util_thread_name(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i8* @fh_log_fmt(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 144)
%12 = tail call i32 @fh_log(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 144, i32* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1)
ret i8* %8
}