#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, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
void verse(char *buffer, int x) {
  switch (x) {
  case 0:
    strcpy(buffer,
           "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");
    break;
  case 1:
    strcpy(buffer, "1 bottle of beer on the wall, 1 bottle of beer.\n"
                   "Take it down and pass it around, "
                   "no more bottles of beer on the wall.\n");
    break;
  case 2:
    strcpy(buffer, "2 bottles of beer on the wall, 2 bottles of beer.\n"
                   "Take one down and pass it around, "
                   "1 bottle of beer on the wall.\n");
    break;
  default:
    sprintf(buffer,
            "%d bottles of beer on the wall, %d bottles of beer.\n"
            "Take one down and pass it around, "
            "%d bottles of beer on the wall.\n",
            x, x, x - 1);
    break;
  }
}


x86 assembly (clang, -O0):
<verse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     1164 <verse+0x44>
jmp    1142 <verse+0x22>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     1179 <verse+0x59>
jmp    1153 <verse+0x33>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     118e <verse+0x6e>
jmp    11a3 <verse+0x83>
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c1 <verse+0xa1>
mov    -0x8(%rbp),%rdi
lea    0xefe(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c1 <verse+0xa1>
mov    -0x8(%rbp),%rdi
lea    0xf60(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c1 <verse+0xa1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%r8d
sub    $0x1,%r8d
lea    0xfb0(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verse>:
cmp    $0x2,%esi
je     113c <verse+0x1c>
mov    %esi,%ecx
cmp    $0x1,%esi
je     1148 <verse+0x28>
test   %ecx,%ecx
jne    1154 <verse+0x34>
lea    0xec9(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    0xfb6(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    0xf33(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    -0x1(%rcx),%r8d
lea    0x100d(%rip),%rsi
mov    %ecx,%edx
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [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"
@.str.1 = [119 x i8] c"1 bottle of beer on the wall, 1 bottle of beer.\0ATake it down and pass it around, no more bottles of beer on the wall.\0A\00"
@.str.2 = [115 x i8] c"2 bottles of beer on the wall, 2 bottles of beer.\0ATake one down and pass it around, 1 bottle of beer on the wall.\0A\00"
@.str.3 = [119 x i8] c"%d bottles of beer on the wall, %d bottles of beer.\0ATake one down and pass it around, %d bottles of beer on the wall.\0A\00"
define void @verse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %15 [
i32 0, label %6
i32 1, label %9
i32 2, label %12
]
6: ; preds = %2
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.2, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %18, i32 %20)
br label %22
22: ; preds = %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [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"
@.str.1 = [119 x i8] c"1 bottle of beer on the wall, 1 bottle of beer.\0ATake it down and pass it around, no more bottles of beer on the wall.\0A\00"
@.str.2 = [115 x i8] c"2 bottles of beer on the wall, 2 bottles of beer.\0ATake one down and pass it around, 1 bottle of beer on the wall.\0A\00"
@.str.3 = [119 x i8] c"%d bottles of beer on the wall, %d bottles of beer.\0ATake one down and pass it around, %d bottles of beer on the wall.\0A\00"
define void @verse(i8* %0, i32 %1) {
switch i32 %1, label %9 [
i32 0, label %3
i32 1, label %5
i32 2, label %7
]
3: ; preds = %2
%4 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str, i64 0, i64 0))
br label %12
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.1, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.2, i64 0, i64 0))
br label %12
9: ; preds = %2
%10 = add nsw i32 %1, -1
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([119 x i8], [119 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %1, i32 %10)
br label %12
12: ; preds = %9, %7, %5, %3
ret void
}