#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void fill_buffer(char *buf, int b) {
  char line[160 / 2];
  if (b > 0) {
    sprintf(buf,
            "%d bottle%s of beer on the wall, %d bottle%s of beer.\n"
            "Take one down and pass it around, ",
            b, (b > 1) ? "s" : "", b, (b > 1) ? "s" : "");
    if (b == 1)
      strcat(buf, "no more bottles of beer on the wall.\n");
    else {
      sprintf(line, "%d bottle%s of beer on the wall.\n", b - 1,
              (b - 1 > 1) ? "s" : "");
      strcat(buf, line);
    }
  } else {
    sprintf(
        buf,
        "No more bottles of beer on the wall, no more bottles of beer.\n"
        "Go to the store and buy some more, 99 bottles of beer on the wall.\n");
  }
}


x86 assembly (clang, -O0):
<fill_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11e6 <fill_buffer+0xc6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%esi
lea    0xf58(%rip),%rcx
lea    0xf08(%rip),%rax
cmp    $0x1,%esi
cmovg  %rax,%rcx
mov    -0xc(%rbp),%r8d
mov    -0xc(%rbp),%esi
lea    0xf3c(%rip),%r9
lea    0xeec(%rip),%rax
cmp    $0x1,%esi
cmovg  %rax,%r9
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11a1 <fill_buffer+0x81>
mov    -0x8(%rbp),%rdi
lea    0xec4(%rip),%rsi
call   1030 <strcat@plt>
jmp    11e1 <fill_buffer+0xc1>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xeea(%rip),%rcx
lea    0xe9a(%rip),%rax
cmp    $0x1,%esi
cmovg  %rax,%rcx
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcat@plt>
jmp    11f8 <fill_buffer+0xd8>
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
test   %esi,%esi
jle    1194 <fill_buffer+0x64>
mov    %esi,%ebx
cmp    $0x1,%esi
lea    0xf54(%rip),%r15
lea    0xf04(%rip),%r12
mov    %r12,%rcx
cmove  %r15,%rcx
lea    0xe9d(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %ebx,%r8d
mov    %rcx,%r9
xor    %eax,%eax
call   1050 <sprintf@plt>
cmp    $0x1,%ebx
jne    11b3 <fill_buffer+0x83>
lea    0xeda(%rip),%rsi
mov    %r14,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcat@plt>
lea    0xf08(%rip),%rsi
mov    $0x82,%edx
mov    %r14,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>
lea    -0x1(%rbx),%edx
cmp    $0x3,%ebx
cmovae %r12,%r15
lea    0xebd(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [89 x i8] c"%d bottle%s of beer on the wall, %d bottle%s of beer.\0ATake one down and pass it around, \00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [38 x i8] c"no more bottles of beer on the wall.\0A\00"
@.str.4 = [34 x i8] c"%d bottle%s of beer on the wall.\0A\00"
@.str.5 = [130 x i8] c"No more bottles of beer on the wall, no more bottles of beer.\0AGo to the store and buy some more, 99 bottles of beer on the wall.\0A\00"
define void @fill_buffer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [80 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
%13 = zext i1 %12 to i64
%14 = select i1 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%15 = load i32, i32* %4
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %14, i32 %15, i8* %19)
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %8
%24 = load i8*, i8** %3
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %39
26: ; preds = %8
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = icmp sgt i32 %31, 1
%33 = zext i1 %32 to i64
%34 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* %34)
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %39
39: ; preds = %26, %23
br label %43
40: ; preds = %2
%41 = load i8*, i8** %3
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %40, %39
ret void
}

LLVM IR (-O2):
@.str = [89 x i8] c"%d bottle%s of beer on the wall, %d bottle%s of beer.\0ATake one down and pass it around, \00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [38 x i8] c"no more bottles of beer on the wall.\0A\00"
@.str.4 = [34 x i8] c"%d bottle%s of beer on the wall.\0A\00"
@.str.5 = [130 x i8] c"No more bottles of beer on the wall, no more bottles of beer.\0AGo to the store and buy some more, 99 bottles of beer on the wall.\0A\00"
define void @fill_buffer(i8* %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = icmp eq i32 %1, 1
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %8, i32 %1, i8* %8)
br i1 %7, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %19
12: ; preds = %6
%13 = add nsw i32 %1, -1
%14 = icmp ugt i32 %1, 2
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %13, i8* %15)
%17 = call i32 @strcat(i8* %0, i8* %4)
br label %19
18: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(130) %0, i8* align 1 dereferenceable(130) getelementptr inbounds ([130 x i8], [130 x i8]* @.str.5, i64 0, i64 0), i64 130, i1 false)
br label %19
19: ; preds = %10, %12, %18
ret void
}