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


x86 assembly (clang, -O0):
<int_from_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <basic_string_from_args@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1184 <int_from_args+0x44>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1190 <int_from_args+0x50>
mov    -0x28(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <arghelp_wanted@plt>
cmp    $0x0,%rax
je     11fc <int_from_args+0xbc>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
lea    0xe46(%rip),%rdi
lea    0xe5a(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11e6 <int_from_args+0xa6>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f7 <int_from_args+0xb7>
mov    -0x2c(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fc <int_from_args+0xbc>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_from_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
xor    %ecx,%ecx
call   1040 <basic_string_from_args@plt>
mov    %rax,%r13
mov    %r14d,%r12d
test   %rax,%rax
je     1183 <int_from_args+0x33>
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <arghelp_wanted@plt>
test   %rax,%rax
je     11cf <int_from_args+0x7f>
lea    0xe67(%rip),%rdi
lea    0xe7b(%rip),%rdx
mov    %r15,%rsi
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13,%r13
je     11c5 <int_from_args+0x75>
lea    0xe68(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11cf <int_from_args+0x7f>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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