#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__ alloca(scalar_t__);
int /*<<< orphan*/ append_import(char const *, char const *, int, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
void def_import(const char *app_name, const char *module, const char *dllext,
                const char *entry, int ord_val, const char *its_name) {
  const char *application_name;
  char *buf;
  if (entry != NULL)
    application_name = entry;
  else {
    if (app_name != NULL)
      application_name = app_name;
    else
      application_name = "";
  }
  if (dllext != NULL) {
    buf = (char *)alloca(strlen(module) + strlen(dllext) + 2);
    sprintf(buf, "%s.%s", module, dllext);
    module = buf;
  }
  append_import(application_name, module, ord_val, its_name);
}


x86 assembly (clang, -O0):
<def_import>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1178 <def_import+0x38>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11a0 <def_import+0x60>
cmpq   $0x0,-0x8(%rbp)
je     1190 <def_import+0x50>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    119b <def_import+0x5b>
lea    0xe6e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11a0 <def_import+0x60>
cmpq   $0x0,-0x18(%rbp)
je     11f5 <def_import+0xb5>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <alloca@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe18(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1030 <append_import@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<def_import>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
test   %rdx,%rdx
je     11a2 <def_import+0x62>
mov    %rdx,%rbx
mov    %rbp,%rdi
mov    %r9,(%rsp)
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <alloca@plt>
mov    %rax,%r14
lea    0xe73(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1060 <sprintf@plt>
mov    (%rsp),%r9
mov    %r14,%rbp
test   %r13,%r13
lea    0xe59(%rip),%rdi
cmovne %r13,%rdi
test   %r12,%r12
cmovne %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r9,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <append_import@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%s.%s\00"
define void @def_import(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%15 = load i8*, i8** %10
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = load i8*, i8** %10
store i8* %18, i8** %13
br label %26
19: ; preds = %6
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %7
store i8* %23, i8** %13
br label %25
24: ; preds = %19
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %13
br label %25
25: ; preds = %24, %22
br label %26
26: ; preds = %25, %17
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = load i8*, i8** %8
%31 = call i64 @strlen(i8* %30)
%32 = load i8*, i8** %9
%33 = call i64 @strlen(i8* %32)
%34 = add nsw i64 %31, %33
%35 = add nsw i64 %34, 2
%36 = call i64 @alloca(i64 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %14
%38 = load i8*, i8** %14
%39 = load i8*, i8** %8
%40 = load i8*, i8** %9
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %40)
%42 = load i8*, i8** %14
store i8* %42, i8** %8
br label %43
43: ; preds = %29, %26
%44 = load i8*, i8** %13
%45 = load i8*, i8** %8
%46 = load i32, i32* %11
%47 = load i8*, i8** %12
%48 = call i32 @append_import(i8* %44, i8* %45, i32 %46, i8* %47)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%s.%s\00"
define void @def_import(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = icmp eq i8* %2, null
br i1 %7, label %16, label %8
8: ; preds = %6
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = tail call i64 @strlen(i8* %2)
%11 = add i64 %9, 2
%12 = add i64 %11, %10
%13 = tail call i64 @alloca(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
br label %16
16: ; preds = %8, %6
%17 = phi i8* [ %14, %8 ], [ %1, %6 ]
%18 = icmp eq i8* %3, null
%19 = icmp eq i8* %0, null
%20 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%21 = select i1 %18, i8* %20, i8* %3
%22 = tail call i32 @append_import(i8* %21, i8* %17, i32 %4, i8* %5)
ret void
}