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

/* Variables and functions */
int adapt_def_region(int /*<<< orphan*/, char *, int);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int def_region(int message, char *category, uint64_t bid, int rid) {
  int error;
  char *prefix = "test_";
  char *buffer = calloc(strlen(prefix) + strlen(category) + 1, sizeof(char));
  strncpy(&buffer[0], prefix, strlen(prefix));
  strncpy(&buffer[strlen(prefix)], category, strlen(category));
  buffer[strlen(prefix) + strlen(category) + 1] = '\0';
  if (message == 1)
    printf("\nDefine region\n");
  error = adapt_def_region(bid, buffer, rid);
  if (message == 1)
    printf("Returned error code: %d\n", error);
  free(buffer);
  return error;
}


x86 assembly (clang, -O0):
<def_region>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x6c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    -0x38(%rbp),%rax
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x1,-0x4(%rbp)
jne    125e <def_region+0xfe>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1080 <adapt_def_region@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    128b <def_region+0x12b>
mov    -0x1c(%rbp),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<def_region>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %edx,(%rsp)
mov    %rsi,%rbp
mov    %edi,%r12d
lea    0xe71(%rip),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
movslq %eax,%r14
add    %r15,%r14
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
cltq
movb   $0x0,(%r15,%rax,1)
cmp    $0x1,%r12d
jne    123f <def_region+0xcf>
lea    0xe08(%rip),%rdi
call   1050 <puts@plt>
mov    (%rsp),%edi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
call   1090 <adapt_def_region@plt>
mov    %eax,%ebp
lea    0xdd2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1250 <def_region+0xe0>
mov    (%rsp),%edi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
call   1090 <adapt_def_region@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test_\00"
@.str.1 = [16 x i8] c"\0ADefine region\0A\00"
@.str.2 = [25 x i8] c"Returned error code: %d\0A\00"
define i32 @def_region(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = load i8*, i8** %10
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 1
%18 = call i8* @calloc(i32 %17, i32 1)
store i8* %18, i8** %11
%19 = load i8*, i8** %11
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8*, i8** %10
%22 = load i8*, i8** %10
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @strncpy(i8* %20, i8* %21, i32 %23)
%25 = load i8*, i8** %11
%26 = load i8*, i8** %10
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8*, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @strncpy(i8* %29, i8* %30, i32 %32)
%34 = load i8*, i8** %11
%35 = load i8*, i8** %10
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %36, %38
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %34, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %47
45: ; preds = %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %4
%48 = load i32, i32* %7
%49 = load i8*, i8** %11
%50 = load i32, i32* %8
%51 = call i32 @adapt_def_region(i32 %48, i8* %49, i32 %50)
store i32 %51, i32* %9
%52 = load i32, i32* %5
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i32, i32* %9
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %47
%58 = load i8*, i8** %11
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %9
ret i32 %60
}

LLVM IR (-O2):
@.str = [6 x i8] c"test_\00"
@.str.2 = [25 x i8] c"Returned error code: %d\0A\00"
@str = [15 x i8] c"\0ADefine region\00"
define i32 @def_region(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = tail call i8* @calloc(i32 %8, i32 1)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = tail call i32 @strlen(i8* %1)
%16 = tail call i32 @strncpy(i8* %14, i8* %1, i32 %15)
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @strlen(i8* %1)
%19 = add i32 %17, 1
%20 = add i32 %19, %18
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %9, i64 %21
store i8 0, i8* %22
%23 = icmp eq i32 %0, 1
br i1 %23, label %26, label %24
24: ; preds = %4
%25 = tail call i32 @adapt_def_region(i32 %2, i8* %9, i32 %3)
br label %30
26: ; preds = %4
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @adapt_def_region(i32 %2, i8* %9, i32 %3)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %24, %26
%31 = phi i32 [ %28, %26 ], [ %25, %24 ]
%32 = tail call i32 @free(i8* %9)
ret i32 %31
}