#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 */
int /*<<< orphan*/ stdimpl_strcpy(char *, char *);
void stdimpl_sprintf(char *out, const char *string, char **va_args) {
  char current;
  while (current = *string++) {
    if (current != '%') {
      *out++ = current;
    } else {
      current = *string++;
      switch (current) {
      case 's':
        out += stdimpl_strcpy(out, *va_args);
        va_args = (char **)((int *)va_args + 1);
        break;
      default:
        out += stdimpl_strcpy(out, "<undef>");
        break;
      }
    }
  }
  *out = '\0';
}


x86 assembly (clang, -O0):
<stdimpl_sprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
cmp    $0x0,%al
je     11e5 <stdimpl_sprintf+0xd5>
movsbl -0x19(%rbp),%eax
cmp    $0x25,%eax
je     1166 <stdimpl_sprintf+0x56>
mov    -0x19(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11e0 <stdimpl_sprintf+0xd0>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
sub    $0x73,%al
jne    11bb <stdimpl_sprintf+0xab>
jmp    118a <stdimpl_sprintf+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1030 <stdimpl_strcpy@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    11db <stdimpl_sprintf+0xcb>
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <stdimpl_strcpy@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11e0 <stdimpl_sprintf+0xd0>
jmp    1124 <stdimpl_sprintf+0x14>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdimpl_sprintf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xed8(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%rax
movzbl (%rax),%ecx
cmp    $0x25,%cl
je     1150 <stdimpl_sprintf+0x40>
test   %cl,%cl
je     1182 <stdimpl_sprintf+0x72>
add    $0x1,%rax
mov    %cl,(%rbx)
add    $0x1,%rbx
jmp    1133 <stdimpl_sprintf+0x23>
nopl   0x0(%rax,%rax,1)
lea    0x2(%rax),%r12
cmpb   $0x73,0x1(%rax)
je     116c <stdimpl_sprintf+0x5c>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <stdimpl_strcpy@plt>
cltq
add    %rax,%rbx
jmp    1130 <stdimpl_sprintf+0x20>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1030 <stdimpl_strcpy@plt>
cltq
add    %rax,%rbx
add    $0x4,%r14
jmp    1130 <stdimpl_sprintf+0x20>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"<undef>\00"
define void @stdimpl_sprintf(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
br label %8
8: ; preds = %46, %3
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %5
%11 = load i8, i8* %9
store i8 %11, i8* %7
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %47
13: ; preds = %8
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 37
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8, i8* %7
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
store i8 %18, i8* %19
br label %46
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
%24 = load i8, i8* %22
store i8 %24, i8* %7
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
switch i32 %26, label %39 [
i32 115, label %27
]
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
%31 = call i32 @stdimpl_strcpy(i8* %28, i8* %30)
%32 = load i8*, i8** %4
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %4
%35 = load i8**, i8*** %6
%36 = bitcast i8** %35 to i32*
%37 = getelementptr inbounds i32, i32* %36, i64 1
%38 = bitcast i32* %37 to i8**
store i8** %38, i8*** %6
br label %45
39: ; preds = %21
%40 = load i8*, i8** %4
%41 = call i32 @stdimpl_strcpy(i8* %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%42 = load i8*, i8** %4
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %4
br label %45
45: ; preds = %39, %27
br label %46
46: ; preds = %45, %17
br label %8
47: ; preds = %8
%48 = load i8*, i8** %4
store i8 0, i8* %48
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"<undef>\00"
define void @stdimpl_sprintf(i8* %0, i8* nocapture %1, i8** nocapture %2) {
br label %4
4: ; preds = %19, %3
%5 = phi i8* [ %23, %19 ], [ %0, %3 ]
%6 = phi i8* [ %16, %19 ], [ %1, %3 ]
%7 = phi i8** [ %26, %19 ], [ %2, %3 ]
br label %8
8: ; preds = %31, %4
%9 = phi i8* [ %5, %4 ], [ %32, %31 ]
%10 = phi i8* [ %6, %4 ], [ %33, %31 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
switch i8 %12, label %13 [
i8 0, label %34
i8 37, label %15
]
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %12, i8* %9
br label %31
15: ; preds = %8
%16 = getelementptr inbounds i8, i8* %10, i64 2
%17 = load i8, i8* %11
%18 = icmp eq i8 %17, 115
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = tail call i32 @stdimpl_strcpy(i8* %9, i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %9, i64 %22
%24 = bitcast i8** %7 to i32*
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = bitcast i32* %25 to i8**
br label %4
27: ; preds = %15
%28 = tail call i32 @stdimpl_strcpy(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %9, i64 %29
br label %31
31: ; preds = %27, %13
%32 = phi i8* [ %14, %13 ], [ %30, %27 ]
%33 = phi i8* [ %11, %13 ], [ %16, %27 ]
br label %8
34: ; preds = %8
store i8 0, i8* %9
ret void
}