#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 */
char *basename(char *);
int bgr_post_receive_hook(int, char **);
int bgr_pre_receive_hook(int, char **);
int bgr_shell(int, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc > 0) {
    if (0 == strcmp(basename(argv[0]), "pre-receive"))
      return bgr_pre_receive_hook(argc, argv);
    if (0 == strcmp(basename(argv[0]), "post-receive"))
      return bgr_post_receive_hook(argc, argv);
  }
  if (argc == 3 && (0 == strcmp(argv[1], "-c"))) {
    return bgr_shell(argc, argv);
  }
  char *ssh_orig = getenv("SSH_ORIGINAL_COMMAND");
  if (argc == 1 && ssh_orig != NULL && argv[0][0] == '/') {
    setenv("SHELL", argv[0], 1);
    char *_argv[] = {argv[0], "-c", ssh_orig};
    return bgr_shell(3, _argv);
  }
  fprintf(stderr, "error: this is a special shell, go away!\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    121f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <basename@plt>
mov    %rax,%rdi
lea    0xe4a(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11dd <main+0x5d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <bgr_pre_receive_hook@plt>
mov    %eax,-0x4(%rbp)
jmp    12ff <main+0x17f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <basename@plt>
mov    %rax,%rdi
lea    0xe19(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    121a <main+0x9a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <bgr_post_receive_hook@plt>
mov    %eax,-0x4(%rbp)
jmp    12ff <main+0x17f>
jmp    121f <main+0x9f>
cmpl   $0x3,-0x8(%rbp)
jne    125f <main+0xdf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde1(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    125f <main+0xdf>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <bgr_shell@plt>
mov    %eax,-0x4(%rbp)
jmp    12ff <main+0x17f>
lea    0xdb6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    12e3 <main+0x163>
cmpq   $0x0,-0x18(%rbp)
je     12e3 <main+0x163>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12e3 <main+0x163>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
lea    0xd58(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rsi
mov    $0x3,%edi
call   10a0 <bgr_shell@plt>
mov    %eax,-0x4(%rbp)
jmp    12ff <main+0x17f>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
test   %edi,%edi
jle    11ef <main+0x6f>
mov    (%rbx),%rdi
call   1090 <basename@plt>
lea    0xe60(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     126b <main+0xeb>
mov    (%rbx),%rdi
call   1090 <basename@plt>
lea    0xe4c(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     127d <main+0xfd>
cmp    $0x3,%ebp
jne    11ef <main+0x6f>
mov    0x8(%rbx),%rdi
lea    0xe38(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     128f <main+0x10f>
lea    0xe26(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x1,%ebp
jne    1248 <main+0xc8>
mov    %rax,%r14
test   %rax,%rax
je     1248 <main+0xc8>
mov    (%rbx),%rsi
cmpb   $0x2f,(%rsi)
jne    1248 <main+0xc8>
lea    0xe1a(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    (%rbx),%rax
mov    %rax,(%rsp)
lea    0xdea(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rsp,%rsi
mov    $0x3,%edi
call   10a0 <bgr_shell@plt>
jmp    1262 <main+0xe2>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <bgr_pre_receive_hook@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <bgr_post_receive_hook@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <bgr_shell@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"pre-receive\00"
@.str.1 = [13 x i8] c"post-receive\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [21 x i8] c"SSH_ORIGINAL_COMMAND\00"
@.str.4 = [6 x i8] c"SHELL\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"error: this is a special shell, go away!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i8* @basename(i8* %13)
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 0, %15
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @bgr_pre_receive_hook(i32 %18, i8** %19)
store i32 %20, i32* %3
br label %78
21: ; preds = %10
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i8* @basename(i8* %24)
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 0, %26
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call i32 @bgr_post_receive_hook(i32 %29, i8** %30)
store i32 %31, i32* %3
br label %78
32: ; preds = %21
br label %33
33: ; preds = %32, %2
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 0, %40
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load i32, i32* %4
%44 = load i8**, i8*** %5
%45 = call i32 @bgr_shell(i32 %43, i8** %44)
store i32 %45, i32* %3
br label %78
46: ; preds = %36, %33
%47 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i8* %47, i8** %6
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %75
50: ; preds = %46
%51 = load i8*, i8** %6
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %75
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 47
br i1 %60, label %61, label %75
61: ; preds = %53
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %64, i32 1)
%66 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 0
%69 = load i8*, i8** %68
store i8* %69, i8** %66
%70 = getelementptr inbounds i8*, i8** %66, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %70
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %6
store i8* %72, i8** %71
%73 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%74 = call i32 @bgr_shell(i32 3, i8** %73)
store i32 %74, i32* %3
br label %78
75: ; preds = %53, %50, %46
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %78
78: ; preds = %75, %61, %42, %28, %17
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [12 x i8] c"pre-receive\00"
@.str.1 = [13 x i8] c"post-receive\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [21 x i8] c"SSH_ORIGINAL_COMMAND\00"
@.str.4 = [6 x i8] c"SHELL\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"error: this is a special shell, go away!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [3 x i8*]
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i8* @basename(i8* %6)
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @bgr_pre_receive_hook(i32 %0, i8** %1)
br label %48
12: ; preds = %5
%13 = load i8*, i8** %1
%14 = tail call i8* @basename(i8* %13)
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @bgr_post_receive_hook(i32 %0, i8** %1)
br label %48
19: ; preds = %12
%20 = icmp eq i32 %0, 3
br i1 %20, label %21, label %28
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 @bgr_shell(i32 3, i8** %1)
br label %48
28: ; preds = %2, %21, %19
%29 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i32 %0, 1
%31 = icmp ne i8* %29, null
%32 = and i1 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %28
%34 = load i8*, i8** %1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 47
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = tail call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 1)
%39 = bitcast [3 x i8*]* %3 to i8*
%40 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%41 = load i8*, i8** %1
store i8* %41, i8** %40
%42 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %42
%43 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* %29, i8** %43
%44 = call i32 @bgr_shell(i32 3, i8** %40)
br label %48
45: ; preds = %33, %28
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %37, %45, %26, %17, %10
%49 = phi i32 [ %11, %10 ], [ %18, %17 ], [ %27, %26 ], [ %44, %37 ], [ 1, %45 ]
ret i32 %49
}