#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 */
struct mg_request_info {
  int dummy;
};

/* Variables and functions */
int str_query_param(struct mg_request_info const *, char const *, char *,
                    int const);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int const);
int str_query_param_def(const struct mg_request_info *request_info,
                        const char *param, const char *def, char *buffer,
                        const int length) {
  int res = str_query_param(request_info, param, buffer, length);
  if (res < 0) {
    strncpy(buffer, def, length);
    return strlen(def);
  }
  return res;
}


x86 assembly (clang, -O0):
<str_query_param_def>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1050 <str_query_param@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    118e <str_query_param_def+0x5e>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1194 <str_query_param_def+0x64>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_query_param_def>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rcx,%rdx
mov    %r8d,%ecx
call   1050 <str_query_param@plt>
test   %eax,%eax
js     1151 <str_query_param_def+0x21>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strlen@plt>

LLVM IR (-O0):
%struct.mg_request_info = type { i32 }
define i32 @str_query_param_def(%struct.mg_request_info* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.mg_request_info*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store %struct.mg_request_info* %0, %struct.mg_request_info** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load %struct.mg_request_info*, %struct.mg_request_info** %7
%14 = load i8*, i8** %8
%15 = load i8*, i8** %10
%16 = load i32, i32* %11
%17 = call i32 @str_query_param(%struct.mg_request_info* %13, i8* %14, i8* %15, i32 %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %5
%21 = load i8*, i8** %10
%22 = load i8*, i8** %9
%23 = load i32, i32* %11
%24 = call i32 @strncpy(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %9
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %6
br label %29
27: ; preds = %5
%28 = load i32, i32* %12
store i32 %28, i32* %6
br label %29
29: ; preds = %27, %20
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
%struct.mg_request_info = type { i32 }
define i32 @str_query_param_def(%struct.mg_request_info* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i32 @str_query_param(%struct.mg_request_info* %0, i8* %1, i8* %3, i32 %4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @strncpy(i8* %3, i8* %2, i32 %4)
%10 = tail call i32 @strlen(i8* %2)
br label %11
11: ; preds = %5, %8
%12 = phi i32 [ %10, %8 ], [ %6, %5 ]
ret i32 %12
}