#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__ arghelp_wanted(int, char **);
char *basic_string_from_args(char const *, int, char **, char *);
scalar_t__ eq_string(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *string_from_args(const char *key, int argc, char *argv[],
                       char *default_value) {
  char *result = basic_string_from_args(key, argc, argv, default_value);
  if (arghelp_wanted(argc, argv)) {
    printf("ARGV %21s %8s default %8s ", key, "<string>",
           (default_value == NULL) ? "NULL" : default_value);
    if ((default_value == NULL && result == NULL) ||
        (default_value != NULL && eq_string(default_value, result)))
      printf("\n");
    else
      printf("commandline %s\n", result);
  }
  return (result);
}


x86 assembly (clang, -O0):
<string_from_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <basic_string_from_args@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <arghelp_wanted@plt>
cmp    $0x0,%rax
je     122f <string_from_args+0xef>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <string_from_args+0x68>
lea    0xe85(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11b0 <string_from_args+0x70>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rcx
lea    0xe41(%rip),%rdi
lea    0xe55(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <string_from_args+0xa3>
cmpq   $0x0,-0x28(%rbp)
je     1205 <string_from_args+0xc5>
cmpq   $0x0,-0x20(%rbp)
je     1218 <string_from_args+0xd8>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <eq_string@plt>
cmp    $0x0,%rax
je     1218 <string_from_args+0xd8>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    122a <string_from_args+0xea>
mov    -0x28(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    122f <string_from_args+0xef>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_from_args>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
call   1040 <basic_string_from_args@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <arghelp_wanted@plt>
test   %rax,%rax
je     11da <string_from_args+0x8a>
test   %r12,%r12
lea    0xea0(%rip),%rcx
cmovne %r12,%rcx
lea    0xe71(%rip),%rdi
lea    0xe85(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rax
or     %r12,%rax
je     11bd <string_from_args+0x6d>
test   %r12,%r12
je     11c9 <string_from_args+0x79>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <eq_string@plt>
test   %rax,%rax
je     11c9 <string_from_args+0x79>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11da <string_from_args+0x8a>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"ARGV %21s %8s default %8s \00"
@.str.1 = [9 x i8] c"<string>\00"
@.str.2 = [5 x i8] c"NULL\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [16 x i8] c"commandline %s\0A\00"
define i8* @string_from_args(i8* %0, i32 %1, i8** %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = load i8**, i8*** %7
%13 = load i8*, i8** %8
%14 = call i8* @basic_string_from_args(i8* %10, i32 %11, i8** %12, i8* %13)
store i8* %14, i8** %9
%15 = load i32, i32* %6
%16 = load i8**, i8*** %7
%17 = call i64 @arghelp_wanted(i32 %15, i8** %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %48
19: ; preds = %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %19
br label %26
24: ; preds = %19
%25 = load i8*, i8** %8
br label %26
26: ; preds = %24, %23
%27 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %23 ], [ %25, %24 ]
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %8
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = icmp eq i8* %32, null
br i1 %33, label %42, label %34
34: ; preds = %31, %26
%35 = load i8*, i8** %8
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i8*, i8** %8
%39 = load i8*, i8** %9
%40 = call i64 @eq_string(i8* %38, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37, %31
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %47
44: ; preds = %37, %34
%45 = load i8*, i8** %9
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %42
br label %48
48: ; preds = %47, %4
%49 = load i8*, i8** %9
ret i8* %49
}

LLVM IR (-O2):
@.str = [27 x i8] c"ARGV %21s %8s default %8s \00"
@.str.1 = [9 x i8] c"<string>\00"
@.str.2 = [5 x i8] c"NULL\00"
@.str.4 = [16 x i8] c"commandline %s\0A\00"
define i8* @string_from_args(i8* %0, i32 %1, i8** %2, i8* %3) {
%5 = tail call i8* @basic_string_from_args(i8* %0, i32 %1, i8** %2, i8* %3)
%6 = tail call i64 @arghelp_wanted(i32 %1, i8** %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = icmp eq i8* %3, null
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = icmp eq i8* %5, null
%13 = select i1 %9, i1 %12, i1 false
br i1 %13, label %18, label %14
14: ; preds = %8
br i1 %9, label %20, label %15
15: ; preds = %14
%16 = tail call i64 @eq_string(i8* %3, i8* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %8, %15
%19 = tail call i32 @putchar(i32 10)
br label %22
20: ; preds = %15, %14
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %22
22: ; preds = %18, %20, %4
ret i8* %5
}