putint(f, i) register f;
{
  char c;
  static char buf[6];
  c = i & 0377;
  if (write(f, &c, 1) != 1)
    return (0);
  c = (i >> 8) & 0377;
  if (write(f, &c, 1) != 1)
    return (0);
  if (write(f, buf, 6) != 6)
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<putint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x1,%eax
je     1151 <putint+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <putint+0xa9>
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x1,%eax
je     1187 <putint+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <putint+0xa9>
mov    -0x8(%rbp),%edi
lea    0x2e98(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x6,%eax
je     11b2 <putint+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <putint+0xa9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %bl,0xf(%rsp)
xor    %ebp,%ebp
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1177 <putint+0x67>
mov    %bh,0xf(%rsp)
xor    %ebp,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1177 <putint+0x67>
lea    0x2eca(%rip),%rsi
mov    %r14d,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    $0x6,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@putint.buf = internal global [6 x i8] zeroinitializer
define i32 @putint(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = and i32 %7, 255
%9 = trunc i32 %8 to i8
store i8 %9, i8* %6
%10 = load i32, i32* %4
%11 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %10, i8* %6, i32 1)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %29
14: ; preds = %2
%15 = load i32, i32* %5
%16 = ashr i32 %15, 8
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
store i8 %18, i8* %6
%19 = load i32, i32* %4
%20 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %19, i8* %6, i32 1)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 0, i32* %3
br label %29
23: ; preds = %14
%24 = load i32, i32* %4
%25 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @putint.buf, i64 0, i64 0), i32 6)
%26 = icmp ne i32 %25, 6
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 0, i32* %3
br label %29
28: ; preds = %23
store i32 1, i32* %3
br label %29
29: ; preds = %28, %27, %22, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@putint.buf = internal global [6 x i8] zeroinitializer
define i32 @putint(i32 %0, i32 %1) {
%3 = alloca i8
%4 = trunc i32 %1 to i8
store i8 %4, i8* %3
%5 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %3, i32 1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = lshr i32 %1, 8
%9 = trunc i32 %8 to i8
store i8 %9, i8* %3
%10 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %3, i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @putint.buf, i64 0, i64 0), i32 6)
%14 = icmp eq i32 %13, 6
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %12, %7, %2
%17 = phi i32 [ 0, %2 ], [ 0, %7 ], [ %15, %12 ]
ret i32 %17
}