#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*/ howmany;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void chug(int beers) {
  char howmany[8], *s;
  s = beers != 1 ? "s" : "";
  printf("%d bottle%s of beer on the wall,\n", beers, s);
  printf("%d bottle%s of beeeeer . . . ,\n", beers, s);
  printf("Take one down, pass it around,\n");
  if (--beers)
    snprintf(howmany, sizeof(howmany), "%d", beers);
  else
    strcpy(howmany, "No more");
  s = beers != 1 ? "s" : "";
  printf("%s bottle%s of beer on the wall.\n", howmany, s);
}


x86 assembly (clang, -O0):
<chug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
lea    0xefe(%rip),%rax
lea    0xeb4(%rip),%rcx
cmp    $0x1,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     11be <chug+0x8e>
lea    -0xc(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x8,%esi
lea    0xeb0(%rip),%rdx
call   1050 <snprintf@plt>
jmp    11ce <chug+0x9e>
lea    -0xc(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edx
lea    0xe6b(%rip),%rax
lea    0xe21(%rip),%rcx
cmp    $0x1,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chug>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0x1,%edi
lea    0xef0(%rip),%r15
lea    0xea6(%rip),%r14
mov    %r14,%rbx
cmove  %r15,%rbx
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee3(%rip),%rdi
call   1040 <puts@plt>
add    $0xffffffff,%ebp
je     11b0 <chug+0x70>
lea    0xea5(%rip),%rdx
mov    %rsp,%rdi
mov    $0x8,%esi
mov    %ebp,%ecx
call   1060 <snprintf@plt>
jmp    11bf <chug+0x7f>
lea    0xe90(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
cmp    $0x1,%ebp
cmove  %r15,%r14
lea    0xe82(%rip),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [34 x i8] c"%d bottle%s of beer on the wall,\0A\00"
@.str.3 = [32 x i8] c"%d bottle%s of beeeeer . . . ,\0A\00"
@.str.4 = [32 x i8] c"Take one down, pass it around,\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [8 x i8] c"No more\00"
@.str.7 = [34 x i8] c"%s bottle%s of beer on the wall.\0A\00"
define void @chug(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 1
%7 = zext i1 %6 to i64
%8 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %8, i8** %4
%9 = load i32, i32* %2
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %10)
%12 = load i32, i32* %2
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %1
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @snprintf(i8* %20, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %26
23: ; preds = %1
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %26
26: ; preds = %23, %19
%27 = load i32, i32* %2
%28 = icmp ne i32 %27, 1
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %30, i8** %4
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %31, i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [34 x i8] c"%d bottle%s of beer on the wall,\0A\00"
@.str.3 = [32 x i8] c"%d bottle%s of beeeeer . . . ,\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [8 x i8] c"No more\00"
@.str.7 = [34 x i8] c"%s bottle%s of beer on the wall.\0A\00"
@str = [31 x i8] c"Take one down, pass it around,\00"
define void @chug(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 1
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %5)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%9 = add nsw i32 %0, -1
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @snprintf(i8* %3, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %15
13: ; preds = %1
%14 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
%16 = icmp eq i32 %9, 1
%17 = select i1 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %3, i8* %17)
ret void
}