#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__ sprintf(char *, char *, int, char);
int /*<<< orphan*/ strcpy(char *, char *);
int fmt1(int t, char s, char **buf, size_t *buflen) {
  char tmp[50];
  size_t len;
  len = ((size_t)sprintf(tmp, "%d%c", t, s));
  if (len + 1 > *buflen)
    return (-1);
  strcpy(*buf, tmp);
  *buf += len;
  *buflen -= len;
  return (0);
}


x86 assembly (clang, -O0):
<fmt1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xeb9(%rip),%rsi
movsbl -0x9(%rbp),%ecx
call   1040 <sprintf@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jbe    1175 <fmt1+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <fmt1+0x8b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x68(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt1>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ecx
mov    %edi,%edx
lea    0xec6(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rcx
mov    $0xffffffff,%eax
cmp    (%r15),%rcx
ja     1166 <fmt1+0x46>
mov    (%r14),%rdi
mov    %rsp,%rsi
call   1030 <strcpy@plt>
add    %rbx,(%r14)
sub    %rbx,(%r15)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%c\00"
define i32 @fmt1(i32 %0, i8 signext %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca [50 x i8]
%11 = alloca i64
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%13 = load i32, i32* %6
%14 = load i8, i8* %7
%15 = call i64 @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13, i8 signext %14)
store i64 %15, i64* %11
%16 = load i64, i64* %11
%17 = add i64 %16, 1
%18 = load i64*, i64** %9
%19 = load i64, i64* %18
%20 = icmp ugt i64 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 -1, i32* %5
br label %35
22: ; preds = %4
%23 = load i8**, i8*** %8
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i64, i64* %11
%28 = load i8**, i8*** %8
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 %27
store i8* %30, i8** %28
%31 = load i64, i64* %11
%32 = load i64*, i64** %9
%33 = load i64, i64* %32
%34 = sub i64 %33, %31
store i64 %34, i64* %32
store i32 0, i32* %5
br label %35
35: ; preds = %22, %21
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%c\00"
define i32 @fmt1(i32 %0, i8 signext %1, i8** nocapture %2, i64* nocapture %3) {
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%7 = call i64 @sprintf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0, i8 signext %1)
%8 = add i64 %7, 1
%9 = load i64, i64* %3
%10 = icmp ugt i64 %8, %9
br i1 %10, label %18, label %11
11: ; preds = %4
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %12, i8* %6)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 %7
store i8* %15, i8** %2
%16 = load i64, i64* %3
%17 = sub i64 %16, %7
store i64 %17, i64* %3
br label %18
18: ; preds = %4, %11
%19 = phi i32 [ 0, %11 ], [ -1, %4 ]
ret i32 %19
}