#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*/ printf(char *, char *);
int snprintf(char *, int, char *, ...);
int main() {
  char buf[10];
  if (snprintf(buf, 10, "hello") >= 10) {
    printf("%s\n", buf);
  }
  if (snprintf(buf, 10, "An extremely long string") >= 10) {
    printf("buf: %s\n", buf);
  }
  if (snprintf(buf, 10, "0%d", 123456789) >= 10) {
    printf("buf: %s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rdi
mov    $0xa,%esi
lea    0xec1(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     115f <main+0x3f>
lea    -0xe(%rbp),%rsi
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    $0xa,%esi
lea    0xe97(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     118f <main+0x6f>
lea    -0xe(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    $0xa,%esi
lea    0xe89(%rip),%rdx
mov    $0x75bcd15,%ecx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     11c4 <main+0xa4>
lea    -0xe(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     1152 <main+0x32>
lea    0xedc(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1030 <printf@plt>
lea    0xead(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     1180 <main+0x60>
lea    0xea9(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1030 <printf@plt>
lea    0xea1(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
mov    $0x75bcd15,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0xa,%eax
jl     11b3 <main+0x93>
lea    0xe76(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [25 x i8] c"An extremely long string\00"
@.str.3 = [9 x i8] c"buf: %s\0A\00"
@.str.4 = [4 x i8] c"0%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
store i32 0, i32* %1
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp sge i32 %4, 10
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %6, %0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %10, i32 10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp sge i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 123456789)
%19 = icmp sge i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [25 x i8] c"An extremely long string\00"
@.str.3 = [9 x i8] c"buf: %s\0A\00"
@.str.4 = [4 x i8] c"0%d\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 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %3, 9
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %7
7: ; preds = %5, %0
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp sgt i32 %8, 9
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %10, %7
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 123456789)
%14 = icmp sgt i32 %13, 9
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %15, %12
ret i32 0
}