long mbar(data, maxl, rcp)
char *data;
long maxl;
struct res *rcp;
{
  char *lp, *skipsp(), *getline();
  char *cntp, *datap = data;
  char *index(), *outp(), *outs(), *outl(), *outc();
  long tmp;
  int id, cnt = 0;
  cntp = datap;
  cnt = 0;
  datap = outs(datap, 0, &maxl);
  while ((lp = skipsp(getline())) != 0) {
    if (sscanf(lp, "%d", &id) != 1)
      fatal("bad resource id");
    datap = outs(datap, id, &maxl);
    cnt++;
  }
  tmp = sizeof(short);
  outs(cntp, cnt, &tmp);
  return (datap - data);
}


x86 assembly (clang, -O0):
<mbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <outs@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getline@plt>
mov    %rax,%rdi
mov    $0x0,%al
call   1050 <skipsp@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1207 <mbar+0xb7>
mov    -0x20(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    -0x3c(%rbp),%rdx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     11e3 <mbar+0x93>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1070 <fatal@plt>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <outs@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1197 <mbar+0x47>
movq   $0x2,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%esi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1060 <outs@plt>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
xor    %ebp,%ebp
lea    0x10(%rsp),%rdx
mov    %rdi,0x18(%rsp)
xor    %esi,%esi
xor    %eax,%eax
call   1060 <outs@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getline@plt>
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <skipsp@plt>
test   %rax,%rax
je     11fe <mbar+0xae>
lea    0xe68(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xe5a(%rip),%r14
xor    %ebp,%ebp
jmp    11dd <mbar+0x8d>
nopl   (%rax)
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <outs@plt>
mov    %rax,%rbx
add    $0x1,%ebp
xor    %eax,%eax
call   1040 <getline@plt>
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <skipsp@plt>
test   %rax,%rax
je     11fe <mbar+0xae>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     11b0 <mbar+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fatal@plt>
jmp    11b0 <mbar+0x60>
movq   $0x2,0x20(%rsp)
lea    0x20(%rsp),%rdx
mov    0x18(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <outs@plt>
sub    %r14,%rbx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.res = type opaque
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"bad resource id\00"
define i64 @mbar(i8* %0, i64 %1, %struct.res* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.res*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store %struct.res* %2, %struct.res** %6
%13 = load i8*, i8** %4
store i8* %13, i8** %9
store i32 0, i32* %12
%14 = load i8*, i8** %9
store i8* %14, i8** %8
store i32 0, i32* %12
%15 = load i8*, i8** %9
%16 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %15, i32 0, i64* %5)
store i8* %16, i8** %9
br label %17
17: ; preds = %27, %3
%18 = call i8* (...) @getline()
%19 = call i8* (i8*, ...) bitcast (i8* (...)* @skipsp to i8* (i8*, ...)*)(i8* %18)
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = call i32 (i8*, i8*, ...) @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @fatal to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i8*, i8** %9
%29 = load i32, i32* %11
%30 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %28, i32 %29, i64* %5)
store i8* %30, i8** %9
%31 = load i32, i32* %12
%32 = add nsw i32 %31, 1
store i32 %32, i32* %12
br label %17
33: ; preds = %17
store i64 2, i64* %10
%34 = load i8*, i8** %8
%35 = load i32, i32* %12
%36 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %34, i32 %35, i64* %10)
%37 = load i8*, i8** %9
%38 = load i8*, i8** %4
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
ret i64 %41
}

LLVM IR (-O2):
%struct.res = type opaque
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"bad resource id\00"
define i64 @mbar(i8* %0, i64 %1, %struct.res* nocapture readnone %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i64 %1, i64* %4
%7 = bitcast i64* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %0, i32 0, i64* %4)
%10 = call i8* (...) @getline()
%11 = call i8* (i8*, ...) bitcast (i8* (...)* @skipsp to i8* (i8*, ...)*)(i8* %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %28, label %13
13: ; preds = %3, %21
%14 = phi i8* [ %26, %21 ], [ %11, %3 ]
%15 = phi i32 [ %24, %21 ], [ 0, %3 ]
%16 = phi i8* [ %23, %21 ], [ %9, %3 ]
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%18 = icmp eq i32 %17, 1
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @fatal to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32, i32* %6
%23 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %16, i32 %22, i64* %4)
%24 = add nuw nsw i32 %15, 1
%25 = call i8* (...) @getline()
%26 = call i8* (i8*, ...) bitcast (i8* (...)* @skipsp to i8* (i8*, ...)*)(i8* %25)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %13
28: ; preds = %21, %3
%29 = phi i8* [ %9, %3 ], [ %23, %21 ]
%30 = phi i32 [ 0, %3 ], [ %24, %21 ]
store i64 2, i64* %5
%31 = call i8* (i8*, i32, i64*, ...) bitcast (i8* (...)* @outs to i8* (i8*, i32, i64*, ...)*)(i8* %0, i32 %30, i64* %5)
%32 = ptrtoint i8* %29 to i64
%33 = ptrtoint i8* %0 to i64
%34 = sub i64 %32, %33
ret i64 %34
}