void chug(register 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)
    sprintf(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     11bb <chug+0x8b>
lea    -0xc(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11cb <chug+0x9b>
lea    -0xc(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edx
lea    0xe6e(%rip),%rax
lea    0xe24(%rip),%rcx
cmp    $0x1,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe79(%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    0xf00(%rip),%r15
lea    0xeb6(%rip),%r14
mov    %r14,%rbx
cmove  %r15,%rbx
lea    0xeaa(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
add    $0xffffffff,%ebp
je     119d <chug+0x6d>
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11ab <chug+0x7b>
movabs $0x65726f6d206f4e,%rax
mov    %rax,(%rsp)
cmp    $0x1,%ebp
cmove  %r15,%r14
lea    0xe8e(%rip),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <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 (i8*, i8*, ...) @sprintf(i8* %20, 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 i8* @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.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 i64
%3 = bitcast i64* %2 to i8*
%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 (i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %14
13: ; preds = %1
store i64 28554795545554766, i64* %2
br label %14
14: ; preds = %13, %11
%15 = icmp eq i32 %9, 1
%16 = select i1 %15, 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)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i64* %2, i8* %16)
ret void
}