#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*/ init_buf(char *, int);
int /*<<< orphan*/ print_buf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int main() {
  char buf[9];
  init_buf(buf, 9);
  print_buf(buf);
  init_buf(buf, 9);
  snprintf(buf, 9, "hello there!");
  print_buf(buf);
  init_buf(buf, 9);
  snprintf(buf, 9, "turtle");
  print_buf(buf);
  init_buf(buf, 9);
  snprintf(buf, 5, "%d", 222222 * 10);
  print_buf(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    -0xd(%rbp),%rdi
call   1030 <print_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
lea    0xe8c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0xd(%rbp),%rdi
call   1030 <print_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
lea    0xe6b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0xd(%rbp),%rdi
call   1030 <print_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    -0xd(%rbp),%rdi
mov    $0x5,%esi
lea    0xe44(%rip),%rdx
mov    $0x21e88c,%ecx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0xd(%rbp),%rdi
call   1030 <print_buf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x7(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
mov    %rbx,%rdi
call   1030 <print_buf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    0xe9d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <print_buf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    0xe7f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <print_buf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <init_buf@plt>
lea    0xe5b(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x21e88c,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <print_buf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hello there!\00"
@.str.1 = [7 x i8] c"turtle\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
store i32 0, i32* %1
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = call i32 @init_buf(i8* %3, i32 9)
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%6 = call i32 @print_buf(i8* %5)
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%8 = call i32 @init_buf(i8* %7, i32 9)
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%12 = call i32 @print_buf(i8* %11)
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%14 = call i32 @init_buf(i8* %13, i32 9)
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %15, i32 9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%18 = call i32 @print_buf(i8* %17)
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%20 = call i32 @init_buf(i8* %19, i32 9)
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%22 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %21, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2222220)
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%24 = call i32 @print_buf(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello there!\00"
@.str.1 = [7 x i8] c"turtle\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%3 = call i32 @init_buf(i8* %2, i32 9)
%4 = call i32 @print_buf(i8* %2)
%5 = call i32 @init_buf(i8* %2, i32 9)
%6 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @print_buf(i8* %2)
%8 = call i32 @init_buf(i8* %2, i32 9)
%9 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @print_buf(i8* %2)
%11 = call i32 @init_buf(i8* %2, i32 9)
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2222220)
%13 = call i32 @print_buf(i8* %2)
ret i32 0
}