#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int sscanf(void *, char *, unsigned int *);
char *strchr(void *, char);
int strlen(void *);
int /*<<< orphan*/ usage(char *);
const unsigned char *extract(void *tree, unsigned long size, const char **pathp,
                             unsigned int *modep) {
  int len = strlen(tree) + 1;
  const unsigned char *sha1 = tree + len;
  const char *path = strchr(tree, ' ');
  if (!path || size < len + 20 || sscanf(tree, "%o", modep) != 1)
    usage("corrupt tree file");
  *pathp = path + 1;
  return sha1;
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11c6 <extract+0x86>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x14,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jb     11c6 <extract+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe48(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11d2 <extract+0x92>
lea    0xe36(%rip),%rdi
call   1060 <usage@plt>
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1196 <extract+0x56>
lea    0x15(%r15),%eax
cltq
cmp    %rbp,%rax
ja     1196 <extract+0x56>
lea    0xe7a(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11a2 <extract+0x62>
lea    0xe66(%rip),%rdi
call   1060 <usage@plt>
movslq %r15d,%rax
add    %r12,%rax
add    $0x1,%rax
add    $0x1,%rbx
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%o\00"
@.str.1 = [18 x i8] c"corrupt tree file\00"
define i8* @extract(i8* %0, i64 %1, i8** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
%15 = load i8*, i8** %5
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr i8, i8* %15, i64 %17
store i8* %18, i8** %10
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 32)
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %4
%24 = load i64, i64* %6
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 20
%27 = sext i32 %26 to i64
%28 = icmp ult i64 %24, %27
br i1 %28, label %34, label %29
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = load i32*, i32** %8
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %31)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %29, %23, %4
%35 = call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %11
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8**, i8*** %7
store i8* %38, i8** %39
%40 = load i8*, i8** %10
ret i8* %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%o\00"
@.str.1 = [18 x i8] c"corrupt tree file\00"
define i8* @extract(i8* %0, i64 %1, i8** nocapture writeonly %2, i32* %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = add nsw i32 %5, 21
%10 = sext i32 %9 to i64
%11 = icmp ugt i64 %10, %1
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %12, %8, %4
%16 = tail call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = add nsw i32 %5, 1
%19 = sext i32 %18 to i64
%20 = getelementptr i8, i8* %0, i64 %19
%21 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %21, i8** %2
ret i8* %20
}