#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *mitkIpFuncMakePicName(char *pic_name, char *extension) {
  char *result_name;
  int length, pos;
  if (pic_name == NULL || extension == NULL)
    return NULL;
  length = strlen(pic_name) + strlen(extension) + 5;
  result_name = (char *)malloc(length * sizeof(char));
  if (result_name == NULL)
    return NULL;
  pos = strstr(pic_name, ".pic") - pic_name;
  if (pos >= 0)
    strncpy(result_name, pic_name, pos);
  else
    strcpy(result_name, pic_name);
  strcat(result_name, extension);
  strcat(result_name, ".pic");
  return (result_name);
}


x86 assembly (clang, -O0):
<mitkIpFuncMakePicName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1186 <mitkIpFuncMakePicName+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1193 <mitkIpFuncMakePicName+0x33>
movq   $0x0,-0x8(%rbp)
jmp    124b <mitkIpFuncMakePicName+0xeb>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x5,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <mitkIpFuncMakePicName+0x80>
movq   $0x0,-0x8(%rbp)
jmp    124b <mitkIpFuncMakePicName+0xeb>
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1080 <strstr@plt>
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1219 <mitkIpFuncMakePicName+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1226 <mitkIpFuncMakePicName+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mitkIpFuncMakePicName>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     11df <mitkIpFuncMakePicName+0x7f>
mov    %rsi,%r14
test   %rsi,%rsi
je     11df <mitkIpFuncMakePicName+0x7f>
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x5,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11bc <mitkIpFuncMakePicName+0x5c>
mov    %rax,%rbx
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
call   1080 <strstr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
sub    %r15d,%eax
js     11c0 <mitkIpFuncMakePicName+0x60>
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    11c5 <mitkIpFuncMakePicName+0x65>
xor    %ebx,%ebx
jmp    11df <mitkIpFuncMakePicName+0x7f>
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c".pic\00"
define i8* @mitkIpFuncMakePicName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i8* null, i8** %3
br label %57
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 5
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %15
store i8* null, i8** %3
br label %57
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = call i8* @strstr(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = load i8*, i8** %4
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %31
%42 = load i8*, i8** %6
%43 = load i8*, i8** %4
%44 = load i32, i32* %8
%45 = call i32 @strncpy(i8* %42, i8* %43, i32 %44)
br label %50
46: ; preds = %31
%47 = load i8*, i8** %6
%48 = load i8*, i8** %4
%49 = call i32 @strcpy(i8* %47, i8* %48)
br label %50
50: ; preds = %46, %41
%51 = load i8*, i8** %6
%52 = load i8*, i8** %5
%53 = call i32 @strcat(i8* %51, i8* %52)
%54 = load i8*, i8** %6
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%56 = load i8*, i8** %6
store i8* %56, i8** %3
br label %57
57: ; preds = %50, %30, %14
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [5 x i8] c".pic\00"
define i8* @mitkIpFuncMakePicName(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %28, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %7, 5
%10 = add i32 %9, %8
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %28, label %14
14: ; preds = %6
%15 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = ptrtoint i8* %15 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = tail call i32 @strncpy(i8* %12, i8* %0, i32 %19)
br label %25
23: ; preds = %14
%24 = tail call i32 @strcpy(i8* %12, i8* %0)
br label %25
25: ; preds = %23, %21
%26 = tail call i32 @strcat(i8* %12, i8* %1)
%27 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %6, %2, %25
%29 = phi i8* [ %12, %25 ], [ null, %2 ], [ null, %6 ]
ret i8* %29
}