#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__ load_config(char *, char **, int);
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ warn(char *);
void merge_config(int argc, char *argv[], int *merged_argc, char **merged_argv,
                  int max_args) {
  if (argc > max_args)
    argc = max_args;
  memcpy(&merged_argv[0], &argv[0], argc * sizeof(char **));
  *merged_argc = argc;
  *merged_argc +=
      load_config("/etc/boardid.config", &merged_argv[argc], max_args - argc);
  if (*merged_argc == max_args)
    warn("Too many arguments specified between the config file and "
         "commandline. Dropping some.");
}


x86 assembly (clang, -O0):
<merge_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    115d <merge_config+0x2d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
sub    -0x4(%rbp),%edx
lea    0xe67(%rip),%rdi
call   1050 <load_config@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
jne    11c8 <merge_config+0x98>
lea    0xe51(%rip),%rdi
call   1030 <warn@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_config>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rcx,%r15
mov    %rdx,%r14
cmp    %r8d,%edi
cmovg  %r8d,%edi
movslq %edi,%rbx
lea    0x0(,%rbx,8),%edx
mov    %rcx,%rdi
call   1040 <memcpy@plt>
mov    %ebx,(%r14)
lea    (%r15,%rbx,8),%rsi
mov    %ebp,%edx
sub    %ebx,%edx
lea    0xe95(%rip),%rdi
call   1050 <load_config@plt>
add    (%r14),%eax
mov    %eax,(%r14)
cmp    %ebp,%eax
jne    1190 <merge_config+0x60>
lea    0xe93(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <warn@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/etc/boardid.config\00"
@.str.1 = [85 x i8] c"Too many arguments specified between the config file and commandline. Dropping some.\00"
define void @merge_config(i32 %0, i8** %1, i32* %2, i8** %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i8** %3, i8*** %9
store i32 %4, i32* %10
%11 = load i32, i32* %6
%12 = load i32, i32* %10
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = load i32, i32* %10
store i32 %15, i32* %6
br label %16
16: ; preds = %14, %5
%17 = load i8**, i8*** %9
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8**, i8*** %7
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i32 @memcpy(i8** %18, i8** %20, i32 %24)
%26 = load i32, i32* %6
%27 = load i32*, i32** %8
store i32 %26, i32* %27
%28 = load i8**, i8*** %9
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i32, i32* %10
%33 = load i32, i32* %6
%34 = sub nsw i32 %32, %33
%35 = call i64 @load_config(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %31, i32 %34)
%36 = load i32*, i32** %8
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = add nsw i64 %38, %35
%40 = trunc i64 %39 to i32
store i32 %40, i32* %36
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = load i32, i32* %10
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %16
%46 = call i32 @warn(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %16
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"/etc/boardid.config\00"
@.str.1 = [85 x i8] c"Too many arguments specified between the config file and commandline. Dropping some.\00"
define void @merge_config(i32 %0, i8** %1, i32* nocapture %2, i8** %3, i32 %4) {
%6 = icmp sgt i32 %0, %4
%7 = select i1 %6, i32 %4, i32 %0
%8 = sext i32 %7 to i64
%9 = shl i32 %7, 3
%10 = tail call i32 @memcpy(i8** %3, i8** %1, i32 %9)
store i32 %7, i32* %2
%11 = getelementptr inbounds i8*, i8** %3, i64 %8
%12 = sub nsw i32 %4, %7
%13 = tail call i64 @load_config(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %11, i32 %12)
%14 = load i32, i32* %2
%15 = trunc i64 %13 to i32
%16 = add i32 %14, %15
store i32 %16, i32* %2
%17 = icmp eq i32 %16, %4
br i1 %17, label %18, label %20
18: ; preds = %5
%19 = tail call i32 @warn(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %5
ret void
}