#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*/ abort();
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int main() {
  char *buffer = malloc(50 * sizeof(char));
  if (buffer == 0) {
    abort();
  }
  sprintf(buffer, "Hello world");
  sprintf(buffer, "Hello %s", "universe");
  sprintf(buffer, "%s %s %s", "aa", "bbbb", "cccccc");
  sprintf(buffer, "%s %s %s %s", "a", "b", "c", "d");
  sprintf(buffer, "%u", (unsigned int)7);
  sprintf(buffer, "%i", 5);
  sprintf(buffer, "%i", -3);
  sprintf(buffer, "%i%i%i%i", 1, 2, 3, 4);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x32,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <main+0x2f>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    0xe82(%rip),%rdx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    0xe72(%rip),%rdx
lea    0xe6e(%rip),%rcx
lea    0xe6c(%rip),%r8
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    0xe4c(%rip),%rdx
lea    0xe4a(%rip),%rcx
lea    0xe4a(%rip),%r8
lea    0xe22(%rip),%r9
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x7,%edx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0xfffffffd,%edx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x32,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1253 <main+0x113>
mov    %rax,%rbx
movabs $0x6f77206f6c6c6548,%rax
20 77 6f
mov    %rax,(%rbx)
movl   $0x646c72,0x8(%rbx)
lea    0xe97(%rip),%rsi
lea    0xe99(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xea3(%rip),%rsi
lea    0xe8a(%rip),%rdx
lea    0xe86(%rip),%rcx
lea    0xe84(%rip),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xe7a(%rip),%rsi
lea    0xe65(%rip),%rdx
lea    0xe63(%rip),%rcx
lea    0xe63(%rip),%r8
lea    0xe3b(%rip),%r9
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xe4c(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xfffffffd,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [9 x i8] c"Hello %s\00"
@.str.2 = [9 x i8] c"universe\00"
@.str.3 = [9 x i8] c"%s %s %s\00"
@.str.4 = [3 x i8] c"aa\00"
@.str.5 = [5 x i8] c"bbbb\00"
@.str.6 = [7 x i8] c"cccccc\00"
@.str.7 = [12 x i8] c"%s %s %s %s\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c"b\00"
@.str.10 = [2 x i8] c"c\00"
@.str.11 = [2 x i8] c"d\00"
@.str.12 = [3 x i8] c"%u\00"
@.str.13 = [3 x i8] c"%i\00"
@.str.14 = [9 x i8] c"%i%i%i%i\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i32 50)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (...) @abort()
unreachable
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%17 = load i8*, i8** %2
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 7)
%19 = load i8*, i8** %2
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i32 5)
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i32 -3)
%23 = load i8*, i8** %2
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0), i32 1, i32 2, i32 3, i32 4)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [9 x i8] c"Hello %s\00"
@.str.2 = [9 x i8] c"universe\00"
@.str.3 = [9 x i8] c"%s %s %s\00"
@.str.4 = [3 x i8] c"aa\00"
@.str.5 = [5 x i8] c"bbbb\00"
@.str.6 = [7 x i8] c"cccccc\00"
@.str.7 = [12 x i8] c"%s %s %s %s\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [2 x i8] c"b\00"
@.str.10 = [2 x i8] c"c\00"
@.str.11 = [2 x i8] c"d\00"
@.str.12 = [3 x i8] c"%u\00"
@.str.13 = [3 x i8] c"%i\00"
@.str.14 = [9 x i8] c"%i%i%i%i\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (...) @abort()
unreachable
5: ; preds = %0
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %1, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 12, i1 false)
%6 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%8 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 7)
%10 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i32 5)
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i32 -3)
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0), i32 1, i32 2, i32 3, i32 4)
%13 = tail call i32 @free(i8* %1)
ret i32 0
}