#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *make_message(char *, char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int main() {
  char buf[10];
  char *p = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  memset(buf, 0x11, sizeof(buf));
  snprintf(buf, sizeof(buf), "%s %s", p, p);
  printf("buf = %s\n", buf);
  printf("hello world\n");
  char *s = make_message("%s", p);
  printf("s = %s\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0xe(%rbp),%rdi
mov    $0x11,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
lea    -0xe(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0xa,%esi
lea    0xea3(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1060 <make_message@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x11,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
lea    0xeb3(%rip),%rdx
lea    0xe84(%rip),%r14
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
call   1070 <make_message@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [40 x i8] c"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@.str.3 = [13 x i8] c"hello world\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [8 x i8] c"s = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 17, i32 10)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @snprintf(i8* %7, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = call i8* @make_message(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [8 x i8] c"s = %s\0A\00"
@str = [12 x i8] c"hello world\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 17, i32 10)
%4 = call i32 @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%7 = call i8* @make_message(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %7)
ret i32 0
}