#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
char *bc_shell_quote(char *);
char *bc_strdup(char *);
char *bc_strdup_printf(char *, char const *, ...);
char *bgr_settings_get_base_dir();
char *bgr_shell_command_parse(char *);
scalar_t__ chdir(char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ lexists(char *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ symlink(char *, char *);
scalar_t__ system(char *);
scalar_t__ unlink(char *);
int bgr_shell(int argc, char *argv[]) {
  int rv = 0;
  char *repo = NULL;
  char *quoted_repo = NULL;
  char *self = getenv("SHELL");
  if (self == NULL) {
    fprintf(stderr, "error: failed to find blogc-git-receiver path\n");
    rv = 1;
    goto cleanup;
  }
  const char *bd = bgr_settings_get_base_dir();
  if (bd == NULL) {
    fprintf(stderr, "error: failed to find base directory path\n");
    rv = 1;
    goto cleanup;
  }
  char *tmp_repo = bgr_shell_command_parse(argv[2]);
  if (tmp_repo == NULL) {
    fprintf(stderr, "error: invalid git-shell command: %s\n", argv[2]);
    rv = 1;
    goto cleanup;
  }
  repo = bc_strdup_printf("%s/repos/%s", bd, tmp_repo);
  quoted_repo = bc_shell_quote(repo);
  free(tmp_repo);
  if (0 == strncmp(argv[2], "git-upload-", 11))
    goto git_exec;
  if (0 != access(repo, F_OK)) {
    char *git_init_cmd =
        bc_strdup_printf("git init --bare %s > /dev/null", quoted_repo);
    if (0 != system(git_init_cmd)) {
      fprintf(stderr, "error: failed to create git repository: %s\n", repo);
      rv = 1;
      free(git_init_cmd);
      goto cleanup;
    }
    free(git_init_cmd);
  }
  if (0 != chdir(repo)) {
    fprintf(stderr, "error: failed to chdir (%s): %s\n", repo, strerror(errno));
    rv = 1;
    goto cleanup;
  }
  if (0 != access("hooks", F_OK)) {
    if (0 != mkdir("hooks", 0777)) {
      fprintf(stderr,
              "error: failed to create directory (%s/hooks): "
              "%s\n",
              repo, strerror(errno));
      rv = 1;
      goto cleanup;
    }
  }
  if (0 != chdir("hooks")) {
    fprintf(stderr, "error: failed to chdir (%s/hooks): %s\n", repo,
            strerror(errno));
    rv = 1;
    goto cleanup;
  }
  if (lexists("pre-receive")) {
    if (0 != unlink("pre-receive")) {
      fprintf(stderr,
              "error: failed to remove old symlink "
              "(%s/hooks/pre-receive): %s\n",
              repo, strerror(errno));
      rv = 1;
      goto cleanup;
    }
  }
  if (0 != symlink(self, "pre-receive")) {
    fprintf(stderr,
            "error: failed to create symlink "
            "(%s/hooks/pre-receive): %s\n",
            repo, strerror(errno));
    rv = 1;
    goto cleanup;
  }
  if (lexists("post-receive")) {
    if (0 != unlink("post-receive")) {
      fprintf(stderr,
              "error: failed to remove old symlink "
              "(%s/hooks/post-receive): %s\n",
              repo, strerror(errno));
      rv = 1;
      goto cleanup;
    }
  }
  if (0 != symlink(self, "post-receive")) {
    fprintf(stderr,
            "error: failed to create symlink "
            "(%s/hooks/post-receive): %s\n",
            repo, strerror(errno));
    rv = 1;
    goto cleanup;
  }
git_exec:
  if (0 != chdir(bd)) {
    fprintf(stderr, "error: failed to chdir (%s): %s\n", bd, strerror(errno));
    rv = 1;
    goto cleanup;
  }
  char buffer[4096];
  char *command = bc_strdup(argv[2]);
  char *p;
  for (p = command; *p != ' ' && *p != '\0'; p++)
    ;
  if (*p == ' ')
    *p = '\0';
  if (sizeof(buffer) < (strlen(command) + strlen(quoted_repo) + 2)) {
    fprintf(stderr, "error: git-shell command is too big\n");
    rv = 1;
    goto cleanup;
  }
  if (0 > snprintf(buffer, sizeof(buffer), "%s %s", command, quoted_repo)) {
    fprintf(stderr, "error: failed to generate git-shell command\n");
    rv = 1;
    goto cleanup;
  }
  free(command);
  free(repo);
  free(quoted_repo);
  if (NULL == getenv("__VALGRIND_ENABLED")) {
    execlp("git-shell", "git-shell", "-c", buffer, NULL);
    fprintf(stderr, "error: failed to execute git-shell\n");
    return 1;
  }
  printf("git-shell -c \"%s\"\n", buffer);
  return 0;
cleanup:
  free(repo);
  free(quoted_repo);
  return rv;
}


x86 assembly (clang, -O0):
<bgr_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10f0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xd80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b7 <bgr_shell+0x67>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    $0x0,%al
call   1130 <bgr_settings_get_base_dir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12f0 <bgr_shell+0xa0>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <bgr_shell_command_parse@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1337 <bgr_shell+0xe7>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1120 <bc_strdup_printf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <bc_shell_quote@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd1c(%rip),%rsi
mov    $0xb,%edx
call   1060 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1393 <bgr_shell+0x143>
jmp    177a <bgr_shell+0x52a>
mov    -0x20(%rbp),%rdi
mov    0x2c2a(%rip),%rax
mov    (%rax),%esi
call   1150 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1419 <bgr_shell+0x1c9>
mov    -0x28(%rbp),%rsi
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1120 <bc_strdup_printf@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10c0 <system@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1410 <bgr_shell+0x1c0>
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xcc9(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
jmp    19ce <bgr_shell+0x77e>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1482 <bgr_shell+0x232>
mov    0x2ba9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x106c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x106c(%rbp),%edi
mov    -0x1068(%rbp),%rdx
mov    %rax,%rcx
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    0x2b3f(%rip),%rax
mov    (%rax),%esi
lea    0xc78(%rip),%rdi
call   1150 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     151b <bgr_shell+0x2cb>
lea    0xc5e(%rip),%rdi
mov    $0x1ff,%esi
call   1070 <mkdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1516 <bgr_shell+0x2c6>
mov    0x2b15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x107c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x107c(%rbp),%edi
mov    -0x1078(%rbp),%rdx
mov    %rax,%rcx
lea    0xc0d(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
jmp    151b <bgr_shell+0x2cb>
lea    0xbe8(%rip),%rdi
call   10b0 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1587 <bgr_shell+0x337>
mov    0x2aa4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    0x2a82(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x108c(%rbp),%edi
mov    -0x1088(%rbp),%rdx
mov    %rax,%rcx
lea    0xbce(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
lea    0xbdb(%rip),%rdi
call   1080 <lexists@plt>
cmp    $0x0,%rax
je     160e <bgr_shell+0x3be>
lea    0xbc5(%rip),%rdi
call   1050 <unlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1609 <bgr_shell+0x3b9>
mov    0x2a22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x109c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1098(%rbp)
mov    0x2a00(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x109c(%rbp),%edi
mov    -0x1098(%rbp),%rdx
mov    %rax,%rcx
lea    0xb7f(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
jmp    160e <bgr_shell+0x3be>
mov    -0x30(%rbp),%rdi
lea    0xb50(%rip),%rsi
call   10e0 <symlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     167e <bgr_shell+0x42e>
mov    0x29ad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10ac(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10a8(%rbp)
mov    0x298b(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x10ac(%rbp),%edi
mov    -0x10a8(%rbp),%rdx
mov    %rax,%rcx
lea    0xb4a(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
lea    0xb6c(%rip),%rdi
call   1080 <lexists@plt>
cmp    $0x0,%rax
je     1705 <bgr_shell+0x4b5>
lea    0xb56(%rip),%rdi
call   1050 <unlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1700 <bgr_shell+0x4b0>
mov    0x292b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10bc(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10b8(%rbp)
mov    0x2909(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x10bc(%rbp),%edi
mov    -0x10b8(%rbp),%rdx
mov    %rax,%rcx
lea    0xb11(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
jmp    1705 <bgr_shell+0x4b5>
mov    -0x30(%rbp),%rdi
lea    0xae1(%rip),%rsi
call   10e0 <symlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1775 <bgr_shell+0x525>
mov    0x28b6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10cc(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10c8(%rbp)
mov    0x2894(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x10cc(%rbp),%edi
mov    -0x10c8(%rbp),%rdx
mov    %rax,%rcx
lea    0xadd(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
jmp    177a <bgr_shell+0x52a>
mov    -0x38(%rbp),%rdi
call   10b0 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     17e3 <bgr_shell+0x593>
mov    0x2848(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10dc(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x10d8(%rbp)
mov    0x2826(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
mov    -0x10dc(%rbp),%edi
mov    -0x10d8(%rbp),%rdx
mov    %rax,%rcx
lea    0x919(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <bc_strdup@plt>
mov    %rax,-0x1058(%rbp)
mov    -0x1058(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x1060(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x10dd(%rbp)
je     1836 <bgr_shell+0x5e6>
mov    -0x1060(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x10dd(%rbp)
mov    -0x10dd(%rbp),%al
test   $0x1,%al
jne    1849 <bgr_shell+0x5f9>
jmp    1865 <bgr_shell+0x615>
jmp    184e <bgr_shell+0x5fe>
mov    -0x1060(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1060(%rbp)
jmp    1805 <bgr_shell+0x5b5>
mov    -0x1060(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1882 <bgr_shell+0x632>
mov    -0x1060(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1058(%rbp),%rdi
call   10a0 <strlen@plt>
mov    %eax,-0x10e4(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <strlen@plt>
mov    %eax,%ecx
mov    -0x10e4(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
movslq %eax,%rcx
mov    $0x1000,%eax
cmp    %rcx,%rax
jae    18de <bgr_shell+0x68e>
mov    0x271e(%rip),%rax
mov    (%rax),%edi
lea    0x9b1(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
lea    -0x1050(%rbp),%rdi
mov    -0x1058(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x1000,%esi
lea    0x9a5(%rip),%rdx
call   10f0 <snprintf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    1932 <bgr_shell+0x6e2>
mov    0x26ca(%rip),%rax
mov    (%rax),%edi
lea    0x988(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    19ce <bgr_shell+0x77e>
mov    -0x1058(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
lea    0x97d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    19af <bgr_shell+0x75f>
lea    -0x1050(%rbp),%rcx
lea    0x96f(%rip),%rsi
lea    0x972(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1160 <execlp@plt>
mov    0x264d(%rip),%rax
mov    (%rax),%edi
lea    0x958(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19e6 <bgr_shell+0x796>
lea    -0x1050(%rbp),%rsi
lea    0x95b(%rip),%rdi
call   10d0 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    19e6 <bgr_shell+0x796>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bgr_shell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r13
lea    0xd95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1350 <bgr_shell+0x100>
mov    %rax,%rbx
xor    %eax,%eax
call   1130 <bgr_settings_get_base_dir@plt>
test   %rax,%rax
je     1362 <bgr_shell+0x112>
mov    %rax,%r12
mov    0x10(%r13),%rdi
call   1100 <bgr_shell_command_parse@plt>
test   %rax,%rax
je     13a6 <bgr_shell+0x156>
mov    %rax,%rbp
lea    0xddb(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1120 <bc_strdup_printf@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <bc_shell_quote@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1040 <free@plt>
mov    0x10(%r13),%rdi
lea    0xdb9(%rip),%rsi
mov    $0xb,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1580 <bgr_shell+0x330>
mov    0x2cd5(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r15,%rdi
call   1150 <access@plt>
test   %rax,%rax
je     13d5 <bgr_shell+0x185>
lea    0xd90(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1120 <bc_strdup_printf@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10c0 <system@plt>
test   %rax,%rax
je     13c6 <bgr_shell+0x176>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
jmp    137f <bgr_shell+0x12f>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
lea    0xca6(%rip),%rsi
jmp    1372 <bgr_shell+0x122>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1110 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    $0x1,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r13),%rdx
lea    0xca6(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1110 <fprintf@plt>
jmp    137c <bgr_shell+0x12c>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    0x2bf3(%rip),%rbp
mov    %r15,%rdi
call   10b0 <chdir@plt>
test   %rax,%rax
je     140a <bgr_shell+0x1ba>
mov    0x2bf7(%rip),%rax
mov    (%rax),%ebx
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xce9(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
jmp    15b0 <bgr_shell+0x360>
mov    0x0(%rbp),%esi
lea    0xcf6(%rip),%rdi
call   1150 <access@plt>
test   %rax,%rax
je     1454 <bgr_shell+0x204>
lea    0xce5(%rip),%rdi
mov    $0x1ff,%esi
call   1070 <mkdir@plt>
test   %rax,%rax
je     1454 <bgr_shell+0x204>
mov    0x2ba5(%rip),%rax
mov    (%rax),%ebx
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcbe(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
lea    0xcaf(%rip),%rdi
call   10b0 <chdir@plt>
test   %rax,%rax
je     1488 <bgr_shell+0x238>
mov    0x2b74(%rip),%rax
mov    (%rax),%ebx
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcbf(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
lea    0xcda(%rip),%rdi
call   1080 <lexists@plt>
test   %rax,%rax
je     14cd <bgr_shell+0x27d>
lea    0xcc9(%rip),%rdi
call   1050 <unlink@plt>
test   %rax,%rax
je     14cd <bgr_shell+0x27d>
mov    0x2b2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcad(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
lea    0xc95(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <symlink@plt>
test   %rax,%rax
je     1504 <bgr_shell+0x2b4>
mov    0x2af8(%rip),%rax
mov    (%rax),%ebx
mov    0x2ae7(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcb6(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
lea    0xce6(%rip),%rdi
call   1080 <lexists@plt>
test   %rax,%rax
je     1549 <bgr_shell+0x2f9>
lea    0xcd5(%rip),%rdi
call   1050 <unlink@plt>
test   %rax,%rax
je     1549 <bgr_shell+0x2f9>
mov    0x2ab3(%rip),%rax
mov    (%rax),%ebx
mov    0x2aa2(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcba(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
lea    0xca1(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <symlink@plt>
test   %rax,%rax
je     1580 <bgr_shell+0x330>
mov    0x2a7c(%rip),%rax
mov    (%rax),%ebx
mov    0x2a6b(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xcc4(%rip),%rsi
jmp    1400 <bgr_shell+0x1b0>
mov    %r12,%rdi
call   10b0 <chdir@plt>
test   %rax,%rax
je     15bf <bgr_shell+0x36f>
mov    0x2a4c(%rip),%rax
mov    (%rax),%ebx
mov    0x2a3b(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xb3e(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1110 <fprintf@plt>
jmp    137f <bgr_shell+0x12f>
mov    0x10(%r13),%rdi
call   1140 <bc_strdup@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     15e5 <bgr_shell+0x395>
cmp    $0x20,%cl
je     15e2 <bgr_shell+0x392>
add    $0x1,%rax
jmp    15d0 <bgr_shell+0x380>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   10a0 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   10a0 <strlen@plt>
add    %ebp,%eax
add    $0xfffff001,%eax
cmp    $0xffffeffe,%eax
ja     1617 <bgr_shell+0x3c7>
mov    0x29d4(%rip),%rax
mov    (%rax),%edi
lea    0xc67(%rip),%rsi
jmp    1685 <bgr_shell+0x435>
lea    0xc83(%rip),%rdx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
mov    %r14,%r8
call   10f0 <snprintf@plt>
test   %rax,%rax
js     1675 <bgr_shell+0x425>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
lea    0xc7f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1691 <bgr_shell+0x441>
lea    0xcb2(%rip),%rdi
mov    %rsp,%rsi
call   10d0 <printf@plt>
xor    %eax,%eax
jmp    1394 <bgr_shell+0x144>
mov    0x2964(%rip),%rax
mov    (%rax),%edi
lea    0xc22(%rip),%rsi
xor    %eax,%eax
call   1110 <fprintf@plt>
jmp    137f <bgr_shell+0x12f>
lea    0xc4f(%rip),%rdi
lea    0xc52(%rip),%rdx
mov    %rsp,%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1160 <execlp@plt>
mov    0x292c(%rip),%rax
mov    (%rax),%edi
lea    0xc37(%rip),%rsi
xor    %eax,%eax
call   1110 <fprintf@plt>
jmp    138f <bgr_shell+0x13f>

LLVM IR (-O0):
@.str = [6 x i8] c"SHELL\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"error: failed to find blogc-git-receiver path\0A\00"
@.str.2 = [43 x i8] c"error: failed to find base directory path\0A\00"
@.str.3 = [38 x i8] c"error: invalid git-shell command: %s\0A\00"
@.str.4 = [12 x i8] c"%s/repos/%s\00"
@.str.5 = [12 x i8] c"git-upload-\00"
@F_OK = global i32 0
@.str.6 = [31 x i8] c"git init --bare %s > /dev/null\00"
@.str.7 = [44 x i8] c"error: failed to create git repository: %s\0A\00"
@.str.8 = [33 x i8] c"error: failed to chdir (%s): %s\0A\00"
@errno = global i32 0
@.str.9 = [6 x i8] c"hooks\00"
@.str.10 = [50 x i8] c"error: failed to create directory (%s/hooks): %s\0A\00"
@.str.11 = [39 x i8] c"error: failed to chdir (%s/hooks): %s\0A\00"
@.str.12 = [12 x i8] c"pre-receive\00"
@.str.13 = [64 x i8] c"error: failed to remove old symlink (%s/hooks/pre-receive): %s\0A\00"
@.str.14 = [60 x i8] c"error: failed to create symlink (%s/hooks/pre-receive): %s\0A\00"
@.str.15 = [13 x i8] c"post-receive\00"
@.str.16 = [65 x i8] c"error: failed to remove old symlink (%s/hooks/post-receive): %s\0A\00"
@.str.17 = [61 x i8] c"error: failed to create symlink (%s/hooks/post-receive): %s\0A\00"
@.str.18 = [37 x i8] c"error: git-shell command is too big\0A\00"
@.str.19 = [6 x i8] c"%s %s\00"
@.str.20 = [45 x i8] c"error: failed to generate git-shell command\0A\00"
@.str.21 = [19 x i8] c"__VALGRIND_ENABLED\00"
@.str.22 = [10 x i8] c"git-shell\00"
@.str.23 = [3 x i8] c"-c\00"
@.str.24 = [36 x i8] c"error: failed to execute git-shell\0A\00"
@.str.25 = [19 x i8] c"git-shell -c \22%s\22\0A\00"
define i32 @bgr_shell(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [4096 x i8]
%14 = alloca i8*
%15 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i8* null, i8** %8
%16 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %233
22: ; preds = %2
%23 = call i8* (...) @bgr_settings_get_base_dir()
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %233
29: ; preds = %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @bgr_shell_command_parse(i8* %32)
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %42
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %40)
store i32 1, i32* %6
br label %233
42: ; preds = %29
%43 = load i8*, i8** %10
%44 = load i8*, i8** %11
%45 = call i8* (i8*, i8*, ...) @bc_strdup_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %43, i8* %44)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = call i8* @bc_shell_quote(i8* %46)
store i8* %47, i8** %8
%48 = load i8*, i8** %11
%49 = call i32 @free(i8* %48)
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 11)
%54 = icmp eq i64 0, %53
br i1 %54, label %55, label %56
55: ; preds = %42
br label %156
56: ; preds = %42
%57 = load i8*, i8** %7
%58 = load i32, i32* @F_OK
%59 = call i64 @access(i8* %57, i32 %58)
%60 = icmp ne i64 0, %59
br i1 %60, label %61, label %76
61: ; preds = %56
%62 = load i8*, i8** %8
%63 = call i8* (i8*, i8*, ...) @bc_strdup_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %62)
store i8* %63, i8** %12
%64 = load i8*, i8** %12
%65 = call i64 @system(i8* %64)
%66 = icmp ne i64 0, %65
br i1 %66, label %67, label %73
67: ; preds = %61
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %7
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %69)
store i32 1, i32* %6
%71 = load i8*, i8** %12
%72 = call i32 @free(i8* %71)
br label %233
73: ; preds = %61
%74 = load i8*, i8** %12
%75 = call i32 @free(i8* %74)
br label %76
76: ; preds = %73, %56
%77 = load i8*, i8** %7
%78 = call i64 @chdir(i8* %77)
%79 = icmp ne i64 0, %78
br i1 %79, label %80, label %86
80: ; preds = %76
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %7
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %82, i8* %84)
store i32 1, i32* %6
br label %233
86: ; preds = %76
%87 = load i32, i32* @F_OK
%88 = call i64 @access(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %87)
%89 = icmp ne i64 0, %88
br i1 %89, label %90, label %100
90: ; preds = %86
%91 = call i64 @mkdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 511)
%92 = icmp ne i64 0, %91
br i1 %92, label %93, label %99
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = load i8*, i8** %7
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %95, i8* %97)
store i32 1, i32* %6
br label %233
99: ; preds = %90
br label %100
100: ; preds = %99, %86
%101 = call i64 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%102 = icmp ne i64 0, %101
br i1 %102, label %103, label %109
103: ; preds = %100
%104 = load i32, i32* @stderr
%105 = load i8*, i8** %7
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0), i8* %105, i8* %107)
store i32 1, i32* %6
br label %233
109: ; preds = %100
%110 = call i64 @lexists(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %122
112: ; preds = %109
%113 = call i64 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%114 = icmp ne i64 0, %113
br i1 %114, label %115, label %121
115: ; preds = %112
%116 = load i32, i32* @stderr
%117 = load i8*, i8** %7
%118 = load i32, i32* @errno
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.13, i64 0, i64 0), i8* %117, i8* %119)
store i32 1, i32* %6
br label %233
121: ; preds = %112
br label %122
122: ; preds = %121, %109
%123 = load i8*, i8** %9
%124 = call i64 @symlink(i8* %123, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%125 = icmp ne i64 0, %124
br i1 %125, label %126, label %132
126: ; preds = %122
%127 = load i32, i32* @stderr
%128 = load i8*, i8** %7
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.14, i64 0, i64 0), i8* %128, i8* %130)
store i32 1, i32* %6
br label %233
132: ; preds = %122
%133 = call i64 @lexists(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %145
135: ; preds = %132
%136 = call i64 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%137 = icmp ne i64 0, %136
br i1 %137, label %138, label %144
138: ; preds = %135
%139 = load i32, i32* @stderr
%140 = load i8*, i8** %7
%141 = load i32, i32* @errno
%142 = call i8* @strerror(i32 %141)
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.16, i64 0, i64 0), i8* %140, i8* %142)
store i32 1, i32* %6
br label %233
144: ; preds = %135
br label %145
145: ; preds = %144, %132
%146 = load i8*, i8** %9
%147 = call i64 @symlink(i8* %146, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%148 = icmp ne i64 0, %147
br i1 %148, label %149, label %155
149: ; preds = %145
%150 = load i32, i32* @stderr
%151 = load i8*, i8** %7
%152 = load i32, i32* @errno
%153 = call i8* @strerror(i32 %152)
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.17, i64 0, i64 0), i8* %151, i8* %153)
store i32 1, i32* %6
br label %233
155: ; preds = %145
br label %156
156: ; preds = %155, %55
%157 = load i8*, i8** %10
%158 = call i64 @chdir(i8* %157)
%159 = icmp ne i64 0, %158
br i1 %159, label %160, label %166
160: ; preds = %156
%161 = load i32, i32* @stderr
%162 = load i8*, i8** %10
%163 = load i32, i32* @errno
%164 = call i8* @strerror(i32 %163)
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %162, i8* %164)
store i32 1, i32* %6
br label %233
166: ; preds = %156
%167 = load i8**, i8*** %5
%168 = getelementptr inbounds i8*, i8** %167, i64 2
%169 = load i8*, i8** %168
%170 = call i8* @bc_strdup(i8* %169)
store i8* %170, i8** %14
%171 = load i8*, i8** %14
store i8* %171, i8** %15
br label %172
172: ; preds = %185, %166
%173 = load i8*, i8** %15
%174 = load i8, i8* %173
%175 = sext i8 %174 to i32
%176 = icmp ne i32 %175, 32
br i1 %176, label %177, label %182
177: ; preds = %172
%178 = load i8*, i8** %15
%179 = load i8, i8* %178
%180 = sext i8 %179 to i32
%181 = icmp ne i32 %180, 0
br label %182
182: ; preds = %177, %172
%183 = phi i1 [ false, %172 ], [ %181, %177 ]
br i1 %183, label %184, label %188
184: ; preds = %182
br label %185
185: ; preds = %184
%186 = load i8*, i8** %15
%187 = getelementptr inbounds i8, i8* %186, i32 1
store i8* %187, i8** %15
br label %172
188: ; preds = %182
%189 = load i8*, i8** %15
%190 = load i8, i8* %189
%191 = sext i8 %190 to i32
%192 = icmp eq i32 %191, 32
br i1 %192, label %193, label %195
193: ; preds = %188
%194 = load i8*, i8** %15
store i8 0, i8* %194
br label %195
195: ; preds = %193, %188
%196 = load i8*, i8** %14
%197 = call i32 @strlen(i8* %196)
%198 = load i8*, i8** %8
%199 = call i32 @strlen(i8* %198)
%200 = add nsw i32 %197, %199
%201 = add nsw i32 %200, 2
%202 = sext i32 %201 to i64
%203 = icmp ult i64 4096, %202
br i1 %203, label %204, label %207
204: ; preds = %195
%205 = load i32, i32* @stderr
%206 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0))
store i32 1, i32* %6
br label %233
207: ; preds = %195
%208 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%209 = load i8*, i8** %14
%210 = load i8*, i8** %8
%211 = call i64 @snprintf(i8* %208, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* %209, i8* %210)
%212 = icmp sgt i64 0, %211
br i1 %212, label %213, label %216
213: ; preds = %207
%214 = load i32, i32* @stderr
%215 = call i32 (i32, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.20, i64 0, i64 0))
store i32 1, i32* %6
br label %233
216: ; preds = %207
%217 = load i8*, i8** %14
%218 = call i32 @free(i8* %217)
%219 = load i8*, i8** %7
%220 = call i32 @free(i8* %219)
%221 = load i8*, i8** %8
%222 = call i32 @free(i8* %221)
%223 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
%224 = icmp eq i8* null, %223
br i1 %224, label %225, label %230
225: ; preds = %216
%226 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%227 = call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i8* %226, i32* null)
%228 = load i32, i32* @stderr
%229 = call i32 (i32, i8*, ...) @fprintf(i32 %228, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.24, i64 0, i64 0))
store i32 1, i32* %3
br label %239
230: ; preds = %216
%231 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%232 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.25, i64 0, i64 0), i8* %231)
store i32 0, i32* %3
br label %239
233: ; preds = %213, %204, %160, %149, %138, %126, %115, %103, %93, %80, %67, %36, %26, %19
%234 = load i8*, i8** %7
%235 = call i32 @free(i8* %234)
%236 = load i8*, i8** %8
%237 = call i32 @free(i8* %236)
%238 = load i32, i32* %6
store i32 %238, i32* %3
br label %239
239: ; preds = %233, %230, %225
%240 = load i32, i32* %3
ret i32 %240
}

LLVM IR (-O2):
@.str = [6 x i8] c"SHELL\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"error: failed to find blogc-git-receiver path\0A\00"
@.str.2 = [43 x i8] c"error: failed to find base directory path\0A\00"
@.str.3 = [38 x i8] c"error: invalid git-shell command: %s\0A\00"
@.str.4 = [12 x i8] c"%s/repos/%s\00"
@.str.5 = [12 x i8] c"git-upload-\00"
@F_OK = global i32 0
@.str.6 = [31 x i8] c"git init --bare %s > /dev/null\00"
@.str.7 = [44 x i8] c"error: failed to create git repository: %s\0A\00"
@.str.8 = [33 x i8] c"error: failed to chdir (%s): %s\0A\00"
@errno = global i32 0
@.str.9 = [6 x i8] c"hooks\00"
@.str.10 = [50 x i8] c"error: failed to create directory (%s/hooks): %s\0A\00"
@.str.11 = [39 x i8] c"error: failed to chdir (%s/hooks): %s\0A\00"
@.str.12 = [12 x i8] c"pre-receive\00"
@.str.13 = [64 x i8] c"error: failed to remove old symlink (%s/hooks/pre-receive): %s\0A\00"
@.str.14 = [60 x i8] c"error: failed to create symlink (%s/hooks/pre-receive): %s\0A\00"
@.str.15 = [13 x i8] c"post-receive\00"
@.str.16 = [65 x i8] c"error: failed to remove old symlink (%s/hooks/post-receive): %s\0A\00"
@.str.17 = [61 x i8] c"error: failed to create symlink (%s/hooks/post-receive): %s\0A\00"
@.str.18 = [37 x i8] c"error: git-shell command is too big\0A\00"
@.str.19 = [6 x i8] c"%s %s\00"
@.str.20 = [45 x i8] c"error: failed to generate git-shell command\0A\00"
@.str.21 = [19 x i8] c"__VALGRIND_ENABLED\00"
@.str.22 = [10 x i8] c"git-shell\00"
@.str.23 = [3 x i8] c"-c\00"
@.str.24 = [36 x i8] c"error: failed to execute git-shell\0A\00"
@.str.25 = [19 x i8] c"git-shell -c \22%s\22\0A\00"
define i32 @bgr_shell(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %156
9: ; preds = %2
%10 = tail call i8* (...) @bgr_settings_get_base_dir()
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %156
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i8* @bgr_shell_command_parse(i8* %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %16
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %156
24: ; preds = %15
%25 = tail call i8* (i8*, i8*, ...) @bc_strdup_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %18)
%26 = tail call i8* @bc_shell_quote(i8* %25)
%27 = tail call i32 @free(i8* %18)
%28 = load i8*, i8** %16
%29 = tail call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 11)
%30 = icmp eq i64 %29, 0
br i1 %30, label %111, label %31
31: ; preds = %24
%32 = load i32, i32* @F_OK
%33 = tail call i64 @access(i8* %25, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %31
%36 = tail call i8* (i8*, i8*, ...) @bc_strdup_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %26)
%37 = tail call i64 @system(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = tail call i32 @free(i8* %36)
br label %45
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %25)
%44 = tail call i32 @free(i8* %36)
br label %156
45: ; preds = %39, %31
%46 = tail call i64 @chdir(i8* %25)
%47 = icmp eq i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %25, i8* %51)
br label %156
53: ; preds = %45
%54 = load i32, i32* @F_OK
%55 = tail call i64 @access(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %65, label %57
57: ; preds = %53
%58 = tail call i64 @mkdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 511)
%59 = icmp eq i64 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = tail call i8* @strerror(i32 %62)
%64 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %25, i8* %63)
br label %156
65: ; preds = %57, %53
%66 = tail call i64 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %73, label %68
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = tail call i8* @strerror(i32 %70)
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %71)
br label %156
73: ; preds = %65
%74 = tail call i64 @lexists(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %84, label %76
76: ; preds = %73
%77 = tail call i64 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %84, label %79
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = tail call i8* @strerror(i32 %81)
%83 = tail call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.13, i64 0, i64 0), i8* %25, i8* %82)
br label %156
84: ; preds = %76, %73
%85 = tail call i64 @symlink(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %92, label %87
87: ; preds = %84
%88 = load i32, i32* @stderr
%89 = load i32, i32* @errno
%90 = tail call i8* @strerror(i32 %89)
%91 = tail call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.14, i64 0, i64 0), i8* %25, i8* %90)
br label %156
92: ; preds = %84
%93 = tail call i64 @lexists(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%94 = icmp eq i64 %93, 0
br i1 %94, label %103, label %95
95: ; preds = %92
%96 = tail call i64 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %103, label %98
98: ; preds = %95
%99 = load i32, i32* @stderr
%100 = load i32, i32* @errno
%101 = tail call i8* @strerror(i32 %100)
%102 = tail call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.16, i64 0, i64 0), i8* %25, i8* %101)
br label %156
103: ; preds = %95, %92
%104 = tail call i64 @symlink(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %111, label %106
106: ; preds = %103
%107 = load i32, i32* @stderr
%108 = load i32, i32* @errno
%109 = tail call i8* @strerror(i32 %108)
%110 = tail call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.17, i64 0, i64 0), i8* %25, i8* %109)
br label %156
111: ; preds = %103, %24
%112 = tail call i64 @chdir(i8* %10)
%113 = icmp eq i64 %112, 0
br i1 %113, label %119, label %114
114: ; preds = %111
%115 = load i32, i32* @stderr
%116 = load i32, i32* @errno
%117 = tail call i8* @strerror(i32 %116)
%118 = tail call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %10, i8* %117)
br label %156
119: ; preds = %111
%120 = load i8*, i8** %16
%121 = tail call i8* @bc_strdup(i8* %120)
br label %122
122: ; preds = %125, %119
%123 = phi i8* [ %121, %119 ], [ %126, %125 ]
%124 = load i8, i8* %123
switch i8 %124, label %125 [
i8 32, label %127
i8 0, label %128
]
125: ; preds = %122
%126 = getelementptr inbounds i8, i8* %123, i64 1
br label %122
127: ; preds = %122
store i8 0, i8* %123
br label %128
128: ; preds = %122, %127
%129 = tail call i32 @strlen(i8* %121)
%130 = tail call i32 @strlen(i8* %26)
%131 = add i32 %129, -4095
%132 = add i32 %131, %130
%133 = icmp ult i32 %132, -4097
br i1 %133, label %134, label %137
134: ; preds = %128
%135 = load i32, i32* @stderr
%136 = tail call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0))
br label %156
137: ; preds = %128
%138 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%139 = call i64 @snprintf(i8* %138, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.19, i64 0, i64 0), i8* %121, i8* %26)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %144
141: ; preds = %137
%142 = load i32, i32* @stderr
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.20, i64 0, i64 0))
br label %156
144: ; preds = %137
%145 = call i32 @free(i8* %121)
%146 = call i32 @free(i8* %25)
%147 = call i32 @free(i8* %26)
%148 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
%149 = icmp eq i8* %148, null
br i1 %149, label %150, label %154
150: ; preds = %144
%151 = call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i8* %138, i32* null)
%152 = load i32, i32* @stderr
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.24, i64 0, i64 0))
br label %161
154: ; preds = %144
%155 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.25, i64 0, i64 0), i8* %138)
br label %161
156: ; preds = %41, %141, %134, %114, %106, %98, %87, %79, %68, %60, %48, %20, %12, %6
%157 = phi i8* [ null, %6 ], [ null, %12 ], [ null, %20 ], [ %26, %114 ], [ %26, %134 ], [ %26, %141 ], [ %26, %41 ], [ %26, %48 ], [ %26, %60 ], [ %26, %68 ], [ %26, %79 ], [ %26, %87 ], [ %26, %98 ], [ %26, %106 ]
%158 = phi i8* [ null, %6 ], [ null, %12 ], [ null, %20 ], [ %25, %114 ], [ %25, %134 ], [ %25, %141 ], [ %25, %41 ], [ %25, %48 ], [ %25, %60 ], [ %25, %68 ], [ %25, %79 ], [ %25, %87 ], [ %25, %98 ], [ %25, %106 ]
%159 = call i32 @free(i8* %158)
%160 = call i32 @free(i8* %157)
br label %161
161: ; preds = %156, %154, %150
%162 = phi i32 [ 1, %156 ], [ 1, %150 ], [ 0, %154 ]
ret i32 %162
}