void put32(len, addr, buf, size, mask) int len;
int addr;
char buf[];
int size, mask;
{
  char *cp = buf;
  int i;
  if (size == 2)
    printf("S1%02X%04X", 2 + len + 1, addr & mask);
  if (size == 3)
    printf("S2%02X%06X", 3 + len + 1, addr & mask);
  if (size == 4)
    printf("S3%02X%08X", 4 + len + 1, addr & mask);
  for (i = 0; i < len; ++i)
    put(*cp++);
  printf("%02X\n", checksum(addr, buf, len, size));
}


x86 assembly (clang, -O0):
<put32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    1178 <put32+0x48>
mov    -0x4(%rbp),%esi
add    $0x2,%esi
add    $0x1,%esi
mov    -0x8(%rbp),%edx
and    -0x18(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    119f <put32+0x6f>
mov    -0x4(%rbp),%esi
add    $0x3,%esi
add    $0x1,%esi
mov    -0x8(%rbp),%edx
and    -0x18(%rbp),%edx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x4,-0x14(%rbp)
jne    11c6 <put32+0x96>
mov    -0x4(%rbp),%esi
add    $0x4,%esi
add    $0x1,%esi
mov    -0x8(%rbp),%edx
and    -0x18(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1200 <put32+0xd0>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
mov    $0x0,%al
call   1030 <put@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cd <put32+0x9d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    $0x0,%al
call   1050 <checksum@plt>
mov    %eax,%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %esi,%r12d
mov    %edi,%r15d
lea    -0x2(%r14),%eax
cmp    $0x2,%eax
ja     1174 <put32+0x44>
cltq
lea    0xecf(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    (%r14,%r15,1),%esi
add    $0x1,%esi
and    %r12d,%r8d
mov    %r8d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    1195 <put32+0x65>
mov    %r15d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl 0x0(%r13,%rbx,1),%edi
xor    %eax,%eax
call   1030 <put@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1180 <put32+0x50>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <checksum@plt>
lea    0xe72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"S1%02X%04X\00"
@.str.1 = [11 x i8] c"S2%02X%06X\00"
@.str.2 = [11 x i8] c"S3%02X%08X\00"
@.str.3 = [6 x i8] c"%02X\0A\00"
define void @put32(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i8*, i8** %8
store i8* %13, i8** %11
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %5
%17 = load i32, i32* %6
%18 = add nsw i32 2, %17
%19 = add nsw i32 %18, 1
%20 = load i32, i32* %7
%21 = load i32, i32* %10
%22 = and i32 %20, %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22)
br label %24
24: ; preds = %16, %5
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i32, i32* %6
%29 = add nsw i32 3, %28
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %7
%32 = load i32, i32* %10
%33 = and i32 %31, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %33)
br label %35
35: ; preds = %27, %24
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 4
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load i32, i32* %6
%40 = add nsw i32 4, %39
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %7
%43 = load i32, i32* %10
%44 = and i32 %42, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %44)
br label %46
46: ; preds = %38, %35
store i32 0, i32* %12
br label %47
47: ; preds = %57, %46
%48 = load i32, i32* %12
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load i8*, i8** %11
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %11
%54 = load i8, i8* %52
%55 = sext i8 %54 to i32
%56 = call i32 (i32, ...) bitcast (i32 (...)* @put to i32 (i32, ...)*)(i32 %55)
br label %57
57: ; preds = %51
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
br label %47
60: ; preds = %47
%61 = load i32, i32* %7
%62 = load i8*, i8** %8
%63 = load i32, i32* %6
%64 = load i32, i32* %9
%65 = call i32 (i32, i8*, i32, i32, ...) bitcast (i32 (...)* @checksum to i32 (i32, i8*, i32, i32, ...)*)(i32 %61, i8* %62, i32 %63, i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %65)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"S1%02X%04X\00"
@.str.1 = [11 x i8] c"S2%02X%06X\00"
@.str.2 = [11 x i8] c"S3%02X%08X\00"
@.str.3 = [6 x i8] c"%02X\0A\00"
@reltable.put32 = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.put32 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.put32 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.put32 to i64)) to i32)]
define void @put32(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = add i32 %3, -2
%7 = icmp ult i32 %6, 3
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = add i32 %3, 1
%10 = sext i32 %6 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.put32 to i8*), i64 %11)
%13 = add nsw i32 %9, %0
%14 = and i32 %4, %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i32 %13, i32 %14)
br label %16
16: ; preds = %5, %8
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %27
18: ; preds = %16, %18
%19 = phi i32 [ %25, %18 ], [ 0, %16 ]
%20 = phi i8* [ %21, %18 ], [ %2, %16 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = tail call i32 (i32, ...) bitcast (i32 (...)* @put to i32 (i32, ...)*)(i32 %23)
%25 = add nuw nsw i32 %19, 1
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %18
27: ; preds = %18, %16
%28 = tail call i32 (i32, i8*, i32, i32, ...) bitcast (i32 (...)* @checksum to i32 (i32, i8*, i32, i32, ...)*)(i32 %1, i8* %2, i32 %0, i32 %3)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %28)
ret void
}