#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__ _stdarg_error(char const *, char *);
int const _stdarg_int(char const *, int const);
int /*<<< orphan*/ _stdarg_str(char const *, char const *);
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
int _stdarg(char const *progname) {
  int ret = 0;
  const int i = 37;
  char const str[] = "Just a simple string.";
  printf("%s: Testing va_arg()\n", progname);
  if (_stdarg_int(progname, i) != i)
    ret += _stdarg_error(progname, "int");
  if (strcmp(_stdarg_str(progname, str), str) != 0)
    ret += _stdarg_error(progname, "char const *");
  return ret;
}


x86 assembly (clang, -O0):
<_stdarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x25,-0x10(%rbp)
mov    0xe8f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8a(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe84(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x25,%esi
call   1030 <_stdarg_int@plt>
cmp    $0x25,%eax
je     11d8 <_stdarg+0x88>
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1040 <_stdarg_error@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <_stdarg_str@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1217 <_stdarg+0xc7>
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1040 <_stdarg_error@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_stdarg>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x2e676e69727473,%rax
mov    %rax,0xe(%rsp)
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1030 <_stdarg_int@plt>
xor    %r14d,%r14d
cmp    $0x25,%eax
je     11ac <_stdarg+0x5c>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <_stdarg_error@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <_stdarg_str@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11db <_stdarg+0x8b>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1040 <_stdarg_error@plt>
add    %eax,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const._stdarg.str = [22 x i8] c"Just a simple string.\00"
@.str = [22 x i8] c"%s: Testing va_arg()\0A\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [13 x i8] c"char const *\00"
define i32 @_stdarg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [22 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 37, i32* %4
%6 = bitcast [22 x i8]* %5 to i8*
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i32 @_stdarg_int(i8* %9, i32 37)
%11 = icmp ne i32 %10, 37
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i64 @_stdarg_error(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = add nsw i64 %16, %14
%18 = trunc i64 %17 to i32
store i32 %18, i32* %3
br label %19
19: ; preds = %12, %1
%20 = load i8*, i8** %2
%21 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 0
%22 = call i32 @_stdarg_str(i8* %20, i8* %21)
%23 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 0
%24 = call i64 @strcmp(i32 %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = load i8*, i8** %2
%28 = call i64 @_stdarg_error(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %26, %19
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@__const._stdarg.str = [22 x i8] c"Just a simple string.\00"
@.str = [22 x i8] c"%s: Testing va_arg()\0A\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [13 x i8] c"char const *\00"
define i32 @_stdarg(i8* %0) {
%2 = alloca [22 x i8]
%3 = getelementptr inbounds [22 x i8], [22 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 @_stdarg_int(i8* %0, i32 37)
%6 = icmp eq i32 %5, 37
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = tail call i64 @_stdarg_error(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = trunc i64 %8 to i32
br label %10
10: ; preds = %7, %1
%11 = phi i32 [ %9, %7 ], [ 0, %1 ]
%12 = call i32 @_stdarg_str(i8* %0, i8* %3)
%13 = call i64 @strcmp(i32 %12, i8* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = call i64 @_stdarg_error(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%17 = trunc i64 %16 to i32
%18 = add i32 %11, %17
br label %19
19: ; preds = %15, %10
%20 = phi i32 [ %18, %15 ], [ %11, %10 ]
ret i32 %20
}