#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 S_IFDIR;
int S_IFREG;
int /*<<< orphan*/ error(char *, unsigned char const *);
int strlen(unsigned char const *);
int parse_zip_file_type(const unsigned char *mbuf, int *p_type) {
  if (strlen(mbuf) != 5) {
    error("file type '%s' is invalid, its length must be 5", mbuf);
    return -1;
  }
  if (mbuf[0] == 'D') {
    *p_type = S_IFDIR | 0775;
  } else if (mbuf[0] == '.') {
    *p_type = S_IFREG | 0644;
  } else {
    error("file type '%s' is invalid", mbuf);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_zip_file_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
je     115e <parse_zip_file_type+0x3e>
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1040 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <parse_zip_file_type+0xba>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x44,%eax
jne    1188 <parse_zip_file_type+0x68>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
or     $0x1fd,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d3 <parse_zip_file_type+0xb3>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2e,%eax
jne    11b2 <parse_zip_file_type+0x92>
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
or     $0x1a4,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11ce <parse_zip_file_type+0xae>
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1040 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <parse_zip_file_type+0xba>
jmp    11d3 <parse_zip_file_type+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_zip_file_type>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x5,%eax
jne    114c <parse_zip_file_type+0x2c>
mov    (%rbx),%al
cmp    $0x44,%al
je     1155 <parse_zip_file_type+0x35>
cmp    $0x2e,%al
jne    116a <parse_zip_file_type+0x4a>
mov    $0x1a4,%eax
mov    0x2e9e(%rip),%rcx
jmp    1161 <parse_zip_file_type+0x41>
lea    0xead(%rip),%rdi
jmp    1171 <parse_zip_file_type+0x51>
mov    $0x1fd,%eax
mov    0x2e6f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    117e <parse_zip_file_type+0x5e>
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
call   1040 <error@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [48 x i8] c"file type '%s' is invalid, its length must be 5\00"
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
@.str.1 = [26 x i8] c"file type '%s' is invalid\00"
define i32 @parse_zip_file_type(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = icmp ne i32 %7, 5
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 -1, i32* %3
br label %37
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 68
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* @S_IFDIR
%20 = or i32 %19, 509
%21 = load i32*, i32** %5
store i32 %20, i32* %21
br label %36
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 46
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @S_IFREG
%30 = or i32 %29, 420
%31 = load i32*, i32** %5
store i32 %30, i32* %31
br label %35
32: ; preds = %22
%33 = load i8*, i8** %4
%34 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 -1, i32* %3
br label %37
35: ; preds = %28
br label %36
36: ; preds = %35, %18
store i32 0, i32* %3
br label %37
37: ; preds = %36, %32, %9
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [48 x i8] c"file type '%s' is invalid, its length must be 5\00"
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
@.str.1 = [26 x i8] c"file type '%s' is invalid\00"
define i32 @parse_zip_file_type(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 5
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
7: ; preds = %2
%8 = load i8, i8* %0
switch i8 %8, label %10 [
i8 68, label %12
i8 46, label %9
]
9: ; preds = %7
br label %12
10: ; preds = %7
%11 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
12: ; preds = %7, %9
%13 = phi i32* [ @S_IFREG, %9 ], [ @S_IFDIR, %7 ]
%14 = phi i32 [ 420, %9 ], [ 509, %7 ]
%15 = load i32, i32* %13
%16 = or i32 %15, %14
store i32 %16, i32* %1
br label %17
17: ; preds = %12, %10, %5
%18 = phi i32 [ -1, %5 ], [ 0, %12 ], [ -1, %10 ]
ret i32 %18
}