#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 */
typedef int mode_t;

/* Variables and functions */
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISREG(int);
scalar_t__ S_ISSOCK(int);
mode_t mode_native_to_git(mode_t native_mode) {
  mode_t perm_bits = native_mode & 07777;
  if (S_ISREG(native_mode))
    return 0100000 | perm_bits;
  if (S_ISDIR(native_mode))
    return 0040000 | perm_bits;
  if (S_ISLNK(native_mode))
    return 0120000 | perm_bits;
  if (S_ISBLK(native_mode))
    return 0060000 | perm_bits;
  if (S_ISCHR(native_mode))
    return 0020000 | perm_bits;
  if (S_ISFIFO(native_mode))
    return 0010000 | perm_bits;
  if (S_ISSOCK(native_mode))
    return 0140000 | perm_bits;
  return perm_bits;
}


x86 assembly (clang, -O0):
<mode_native_to_git>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%rax
je     11a8 <mode_native_to_git+0x38>
mov    -0xc(%rbp),%eax
or     $0x8000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11ca <mode_native_to_git+0x5a>
mov    -0xc(%rbp),%eax
or     $0x4000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     11ec <mode_native_to_git+0x7c>
mov    -0xc(%rbp),%eax
or     $0xa000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     120e <mode_native_to_git+0x9e>
mov    -0xc(%rbp),%eax
or     $0x6000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1230 <mode_native_to_git+0xc0>
mov    -0xc(%rbp),%eax
or     $0x2000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1252 <mode_native_to_git+0xe2>
mov    -0xc(%rbp),%eax
or     $0x1000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0x8(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1274 <mode_native_to_git+0x104>
mov    -0xc(%rbp),%eax
or     $0xc000,%eax
mov    %eax,-0x4(%rbp)
jmp    127a <mode_native_to_git+0x10a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_native_to_git>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %edi,%ebx
and    $0xfff,%ebx
call   1070 <S_ISREG@plt>
test   %rax,%rax
je     118f <mode_native_to_git+0x1f>
or     $0x8000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     11a3 <mode_native_to_git+0x33>
or     $0x4000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     11b7 <mode_native_to_git+0x47>
or     $0xa000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
je     11cb <mode_native_to_git+0x5b>
or     $0x6000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1080 <S_ISCHR@plt>
test   %rax,%rax
je     11df <mode_native_to_git+0x6f>
or     $0x2000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     11f3 <mode_native_to_git+0x83>
or     $0x1000,%ebx
jmp    1208 <mode_native_to_git+0x98>
mov    %ebp,%edi
call   1050 <S_ISSOCK@plt>
lea    0xc000(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mode_native_to_git(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, 4095
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = call i64 @S_ISREG(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %4
%12 = or i32 32768, %11
store i32 %12, i32* %2
br label %57
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %4
%19 = or i32 16384, %18
store i32 %19, i32* %2
br label %57
20: ; preds = %13
%21 = load i32, i32* %3
%22 = call i64 @S_ISLNK(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %4
%26 = or i32 40960, %25
store i32 %26, i32* %2
br label %57
27: ; preds = %20
%28 = load i32, i32* %3
%29 = call i64 @S_ISBLK(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %4
%33 = or i32 24576, %32
store i32 %33, i32* %2
br label %57
34: ; preds = %27
%35 = load i32, i32* %3
%36 = call i64 @S_ISCHR(i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %4
%40 = or i32 8192, %39
store i32 %40, i32* %2
br label %57
41: ; preds = %34
%42 = load i32, i32* %3
%43 = call i64 @S_ISFIFO(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %4
%47 = or i32 4096, %46
store i32 %47, i32* %2
br label %57
48: ; preds = %41
%49 = load i32, i32* %3
%50 = call i64 @S_ISSOCK(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %4
%54 = or i32 49152, %53
store i32 %54, i32* %2
br label %57
55: ; preds = %48
%56 = load i32, i32* %4
store i32 %56, i32* %2
br label %57
57: ; preds = %55, %52, %45, %38, %31, %24, %17, %10
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
define i32 @mode_native_to_git(i32 %0) {
%2 = and i32 %0, 4095
%3 = tail call i64 @S_ISREG(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = or i32 %2, 32768
br label %37
7: ; preds = %1
%8 = tail call i64 @S_ISDIR(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = or i32 %2, 16384
br label %37
12: ; preds = %7
%13 = tail call i64 @S_ISLNK(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = or i32 %2, 40960
br label %37
17: ; preds = %12
%18 = tail call i64 @S_ISBLK(i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = or i32 %2, 24576
br label %37
22: ; preds = %17
%23 = tail call i64 @S_ISCHR(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = or i32 %2, 8192
br label %37
27: ; preds = %22
%28 = tail call i64 @S_ISFIFO(i32 %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = or i32 %2, 4096
br label %37
32: ; preds = %27
%33 = tail call i64 @S_ISSOCK(i32 %0)
%34 = icmp eq i64 %33, 0
%35 = or i32 %2, 49152
%36 = select i1 %34, i32 %2, i32 %35
br label %37
37: ; preds = %32, %30, %25, %20, %15, %10, %5
%38 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ %21, %20 ], [ %26, %25 ], [ %31, %30 ], [ %36, %32 ]
ret i32 %38
}