strtim(buf) char *buf;
{
  int x, y, z;
  switch (sscanf(buf, "%d:%d:%d", &x, &y, &z)) {
  case 1:
    return (x);
  case 2:
    return (60 * x + y);
  case 3:
    return (3600 * x + 60 * y + z);
  default:
    return (-1);
  }
}


x86 assembly (clang, -O0):
<strtim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed9(%rip),%rsi
xor    %eax,%eax
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0x1,%eax
je     116f <strtim+0x5f>
jmp    114d <strtim+0x3d>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     117a <strtim+0x6a>
jmp    115e <strtim+0x4e>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     1189 <strtim+0x79>
jmp    11a1 <strtim+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <strtim+0x98>
imul   $0x3c,-0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <strtim+0x98>
imul   $0xe10,-0x14(%rbp),%eax
imul   $0x3c,-0x18(%rbp),%ecx
add    %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <strtim+0x98>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtim>:
sub    $0x18,%rsp
lea    0xee5(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x14(%rsp),%r8
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x3,%eax
je     1150 <strtim+0x40>
mov    %eax,%ecx
cmp    $0x2,%eax
je     1168 <strtim+0x58>
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    1163 <strtim+0x53>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret
imul   $0xe10,0xc(%rsp),%ecx
imul   $0x3c,0x10(%rsp),%eax
add    %ecx,%eax
add    0x14(%rsp),%eax
add    $0x18,%rsp
ret
imul   $0x3c,0xc(%rsp),%eax
add    0x10(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d:%d:%d\00"
define i32 @strtim(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 (i8*, i8*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
switch i32 %8, label %24 [
i32 1, label %9
i32 2, label %11
i32 3, label %16
]
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %25
11: ; preds = %1
%12 = load i32, i32* %4
%13 = mul nsw i32 60, %12
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
store i32 %15, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* %4
%18 = mul nsw i32 3600, %17
%19 = load i32, i32* %5
%20 = mul nsw i32 60, %19
%21 = add nsw i32 %18, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
store i32 %23, i32* %2
br label %25
24: ; preds = %1
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %16, %11, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d:%d:%d\00"
define i32 @strtim(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
switch i32 %8, label %24 [
i32 1, label %9
i32 2, label %11
i32 3, label %16
]
9: ; preds = %1
%10 = load i32, i32* %2
br label %24
11: ; preds = %1
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, 60
%14 = load i32, i32* %3
%15 = add nsw i32 %13, %14
br label %24
16: ; preds = %1
%17 = load i32, i32* %2
%18 = mul nsw i32 %17, 3600
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 60
%21 = add nsw i32 %20, %18
%22 = load i32, i32* %4
%23 = add nsw i32 %21, %22
br label %24
24: ; preds = %1, %16, %11, %9
%25 = phi i32 [ %23, %16 ], [ %15, %11 ], [ %10, %9 ], [ -1, %1 ]
ret i32 %25
}