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

/* Variables and functions */
int checkout_commit(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ fs_check_dir_exists(char *);
int /*<<< orphan*/ fs_cp(char *, char *);
scalar_t__ get_branch_number(char const *);
scalar_t__ is_it_a_commit_id(char const *);
int /*<<< orphan*/ read_string_from_file(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write_string_to_file(char *, char const *);
int beargit_checkout(const char *arg, int new_branch) {
  char current_branch[128];
  read_string_from_file(".beargit/.current_branch", current_branch, 128);
  if (strlen(current_branch)) {
    char current_branch_file[128 + 100];
    sprintf(current_branch_file, ".beargit/.branch_%s", current_branch);
    fs_cp(".beargit/.prev", current_branch_file);
  }
  if (is_it_a_commit_id(arg)) {
    char commit_dir[512 + 100] = ".beargit/";
    strcat(commit_dir, arg);
    if (!fs_check_dir_exists(commit_dir)) {
      fprintf(stderr, "ERROR: Commit %s does not exist\n", arg);
      return 1;
    }
    write_string_to_file(".beargit/.current_branch", "");
    return checkout_commit(arg);
  }
  const char *branch_name = arg;
  int branch_exists = (get_branch_number(branch_name) >= 0);
  if (branch_exists && new_branch) {
    fprintf(stderr, "ERROR: A branch named %s already exists\n", branch_name);
    return 1;
  } else if (!branch_exists && !new_branch) {
    fprintf(stderr, "ERROR: No branch %s exists\n", branch_name);
    return 1;
  }
  char branch_file[512] = ".beargit/.branch_";
  strcat(branch_file, branch_name);
  if (new_branch) {
    FILE *fbranches = fopen(".beargit/.branches", "a");
    fprintf(fbranches, "%s\n", branch_name);
    fclose(fbranches);
    fs_cp(".beargit/.prev", branch_file);
  }
  write_string_to_file(".beargit/.current_branch", branch_name);
  char branch_head_commit_id[(40 + 1)];
  read_string_from_file(branch_file, branch_head_commit_id, (40 + 1));
  return checkout_commit(branch_head_commit_id);
}


x86 assembly (clang, -O0):
<beargit_checkout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x80,%edx
call   10e0 <read_string_from_file@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     124d <beargit_checkout+0x6d>
lea    -0x190(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xde4(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x190(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   10b0 <fs_cp@plt>
mov    -0x10(%rbp),%rdi
call   1050 <is_it_a_commit_id@plt>
cmp    $0x0,%rax
je     12e7 <beargit_checkout+0x107>
lea    -0x400(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x264,%edx
call   1090 <memcpy@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <strcat@plt>
lea    -0x400(%rbp),%rdi
call   10a0 <fs_check_dir_exists@plt>
cmp    $0x0,%eax
jne    12c3 <beargit_checkout+0xe3>
mov    0x2d3c(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd8a(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1457 <beargit_checkout+0x277>
lea    0xd36(%rip),%rdi
lea    0xde9(%rip),%rsi
call   1100 <write_string_to_file@plt>
mov    -0x10(%rbp),%rdi
call   1060 <checkout_commit@plt>
mov    %eax,-0x4(%rbp)
jmp    1457 <beargit_checkout+0x277>
mov    -0x10(%rbp),%rax
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
call   1070 <get_branch_number@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40c(%rbp)
cmpl   $0x0,-0x40c(%rbp)
je     1350 <beargit_checkout+0x170>
cmpl   $0x0,-0x14(%rbp)
je     1350 <beargit_checkout+0x170>
mov    0x2cb2(%rip),%rax
mov    (%rax),%rdi
mov    -0x408(%rbp),%rdx
lea    0xd1e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1457 <beargit_checkout+0x277>
cmpl   $0x0,-0x40c(%rbp)
jne    1390 <beargit_checkout+0x1b0>
cmpl   $0x0,-0x14(%rbp)
jne    1390 <beargit_checkout+0x1b0>
mov    0x2c72(%rip),%rax
mov    (%rax),%rdi
mov    -0x408(%rbp),%rdx
lea    0xd07(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1457 <beargit_checkout+0x277>
jmp    1395 <beargit_checkout+0x1b5>
lea    -0x610(%rbp),%rdi
lea    0xf8d(%rip),%rsi
mov    $0x200,%edx
call   1090 <memcpy@plt>
lea    -0x610(%rbp),%rdi
mov    -0x408(%rbp),%rsi
call   10d0 <strcat@plt>
cmpl   $0x0,-0x14(%rbp)
je     141d <beargit_checkout+0x23d>
lea    0xcd1(%rip),%rdi
lea    0xcdd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x618(%rbp)
mov    -0x618(%rbp),%rdi
mov    -0x408(%rbp),%rdx
lea    0xcbe(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x618(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x610(%rbp),%rsi
lea    0xc15(%rip),%rdi
call   10b0 <fs_cp@plt>
mov    -0x408(%rbp),%rsi
lea    0xbd5(%rip),%rdi
call   1100 <write_string_to_file@plt>
lea    -0x610(%rbp),%rdi
lea    -0x650(%rbp),%rsi
mov    $0x29,%edx
call   10e0 <read_string_from_file@plt>
lea    -0x650(%rbp),%rdi
call   1060 <checkout_commit@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beargit_checkout>:
push   %rbp
push   %r14
push   %rbx
sub    $0x320,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe18(%rip),%rdi
lea    0x30(%rsp),%rsi
mov    $0x80,%edx
call   10d0 <read_string_from_file@plt>
cmpb   $0x0,0x30(%rsp)
je     1229 <beargit_checkout+0x59>
lea    0xe14(%rip),%rsi
lea    0xb0(%rsp),%rbp
lea    0x30(%rsp),%rdx
mov    %rbp,%rdi
call   10e0 <sprintf@plt>
lea    0xe0c(%rip),%rdi
mov    %rbp,%rsi
call   10a0 <fs_cp@plt>
mov    %rbx,%rdi
call   1040 <is_it_a_commit_id@plt>
test   %rax,%rax
je     1286 <beargit_checkout+0xb6>
lea    0xe83(%rip),%rsi
lea    0xb0(%rsp),%rbp
mov    $0x264,%edx
mov    %rbp,%rdi
call   1080 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
call   1090 <fs_check_dir_exists@plt>
test   %eax,%eax
je     12ab <beargit_checkout+0xdb>
lea    0xd90(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10f0 <write_string_to_file@plt>
mov    %rbx,%rdi
call   1050 <checkout_commit@plt>
jmp    12e6 <beargit_checkout+0x116>
mov    %rbx,%rdi
call   1060 <get_branch_number@plt>
test   %r14d,%r14d
je     12be <beargit_checkout+0xee>
test   %rax,%rax
js     12be <beargit_checkout+0xee>
mov    0x2d41(%rip),%rax
mov    (%rax),%rdi
lea    0xdb4(%rip),%rsi
jmp    12d9 <beargit_checkout+0x109>
mov    0x2d2e(%rip),%rax
mov    (%rax),%rdi
lea    0xd80(%rip),%rsi
jmp    12d9 <beargit_checkout+0x109>
test   %r14d,%r14d
jne    12f2 <beargit_checkout+0x122>
test   %rax,%rax
jns    12f2 <beargit_checkout+0x122>
mov    0x2d11(%rip),%rax
mov    (%rax),%rdi
lea    0xdad(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x320,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x1037(%rip),%rsi
lea    0xb0(%rsp),%rbp
mov    $0x200,%edx
mov    %rbp,%rdi
call   1080 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <strcat@plt>
test   %r14d,%r14d
je     1362 <beargit_checkout+0x192>
lea    0xd7d(%rip),%rdi
lea    0xd89(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
lea    0xd7c(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xcd8(%rip),%rdi
lea    0xb0(%rsp),%rsi
call   10a0 <fs_cp@plt>
lea    0xc97(%rip),%rdi
mov    %rbx,%rsi
call   10f0 <write_string_to_file@plt>
lea    0xb0(%rsp),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x29,%edx
call   10d0 <read_string_from_file@plt>
jmp    127c <beargit_checkout+0xac>

LLVM IR (-O0):
@.str = [25 x i8] c".beargit/.current_branch\00"
@.str.1 = [20 x i8] c".beargit/.branch_%s\00"
@.str.2 = [15 x i8] c".beargit/.prev\00"
@__const.beargit_checkout.commit_dir = [612 x i8] c".beargit/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32* null
@.str.3 = [33 x i8] c"ERROR: Commit %s does not exist\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [41 x i8] c"ERROR: A branch named %s already exists\0A\00"
@.str.6 = [28 x i8] c"ERROR: No branch %s exists\0A\00"
@__const.beargit_checkout.branch_file = [512 x i8] c".beargit/.branch_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.7 = [19 x i8] c".beargit/.branches\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [4 x i8] c"%s\0A\00"
define i32 @beargit_checkout(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca [228 x i8]
%8 = alloca [612 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [512 x i8]
%12 = alloca i32*
%13 = alloca [41 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = call i32 @read_string_from_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14, i32 128)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = getelementptr inbounds [228 x i8], [228 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [228 x i8], [228 x i8]* %7, i64 0, i64 0
%24 = call i32 @fs_cp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %2
%26 = load i8*, i8** %4
%27 = call i64 @is_it_a_commit_id(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = bitcast [612 x i8]* %8 to i8*
%31 = getelementptr inbounds [612 x i8], [612 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = getelementptr inbounds [612 x i8], [612 x i8]* %8, i64 0, i64 0
%35 = call i32 @fs_check_dir_exists(i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %29
%38 = load i32*, i32** @stderr
%39 = load i8*, i8** %4
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %95
41: ; preds = %29
%42 = call i32 @write_string_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%43 = load i8*, i8** %4
%44 = call i32 @checkout_commit(i8* %43)
store i32 %44, i32* %3
br label %95
45: ; preds = %25
%46 = load i8*, i8** %4
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = call i64 @get_branch_number(i8* %47)
%49 = icmp sge i64 %48, 0
%50 = zext i1 %49 to i32
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %45
%54 = load i32, i32* %5
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = load i32*, i32** @stderr
%58 = load i8*, i8** %9
%59 = call i32 @fprintf(i32* %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %58)
store i32 1, i32* %3
br label %95
60: ; preds = %53, %45
%61 = load i32, i32* %10
%62 = icmp ne i32 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %60
%64 = load i32, i32* %5
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %63
%67 = load i32*, i32** @stderr
%68 = load i8*, i8** %9
%69 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %68)
store i32 1, i32* %3
br label %95
70: ; preds = %63, %60
br label %71
71: ; preds = %70
%72 = bitcast [512 x i8]* %11 to i8*
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%74 = load i8*, i8** %9
%75 = call i32 @strcat(i8* %73, i8* %74)
%76 = load i32, i32* %5
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %87
78: ; preds = %71
%79 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %79, i32** %12
%80 = load i32*, i32** %12
%81 = load i8*, i8** %9
%82 = call i32 @fprintf(i32* %80, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %81)
%83 = load i32*, i32** %12
%84 = call i32 @fclose(i32* %83)
%85 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%86 = call i32 @fs_cp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %78, %71
%88 = load i8*, i8** %9
%89 = call i32 @write_string_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %88)
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%91 = getelementptr inbounds [41 x i8], [41 x i8]* %13, i64 0, i64 0
%92 = call i32 @read_string_from_file(i8* %90, i8* %91, i32 41)
%93 = getelementptr inbounds [41 x i8], [41 x i8]* %13, i64 0, i64 0
%94 = call i32 @checkout_commit(i8* %93)
store i32 %94, i32* %3
br label %95
95: ; preds = %87, %66, %56, %41, %37
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@.str = [25 x i8] c".beargit/.current_branch\00"
@.str.1 = [20 x i8] c".beargit/.branch_%s\00"
@.str.2 = [15 x i8] c".beargit/.prev\00"
@__const.beargit_checkout.commit_dir = [612 x i8] c".beargit/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32* null
@.str.3 = [33 x i8] c"ERROR: Commit %s does not exist\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [41 x i8] c"ERROR: A branch named %s already exists\0A\00"
@.str.6 = [28 x i8] c"ERROR: No branch %s exists\0A\00"
@__const.beargit_checkout.branch_file = [512 x i8] c".beargit/.branch_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.7 = [19 x i8] c".beargit/.branches\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [4 x i8] c"%s\0A\00"
define i32 @beargit_checkout(i8* %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = alloca [228 x i8]
%5 = alloca [612 x i8]
%6 = alloca [512 x i8]
%7 = alloca [41 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = call i32 @read_string_from_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8, i32 128)
%10 = load i8, i8* %8
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = getelementptr inbounds [228 x i8], [228 x i8]* %4, i64 0, i64 0
%14 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%15 = call i32 @fs_cp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %16
16: ; preds = %12, %2
%17 = call i64 @is_it_a_commit_id(i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = getelementptr inbounds [612 x i8], [612 x i8]* %5, i64 0, i64 0
%21 = call i32 @strcat(i8* %20, i8* %0)
%22 = call i32 @fs_check_dir_exists(i8* %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32*, i32** @stderr
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %30
27: ; preds = %19
%28 = call i32 @write_string_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @checkout_commit(i8* %0)
br label %30
30: ; preds = %27, %24
%31 = phi i32 [ %29, %27 ], [ 1, %24 ]
br label %58
32: ; preds = %16
%33 = call i64 @get_branch_number(i8* %0)
%34 = icmp sgt i64 %33, -1
%35 = icmp ne i32 %1, 0
%36 = and i1 %35, %34
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32*, i32** @stderr
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %58
40: ; preds = %32
%41 = or i1 %35, %34
br i1 %41, label %45, label %42
42: ; preds = %40
%43 = load i32*, i32** @stderr
%44 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %58
45: ; preds = %40
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%47 = call i32 @strcat(i8* %46, i8* %0)
br i1 %35, label %48, label %53
48: ; preds = %45
%49 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%50 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %0)
%51 = call i32 @fclose(i32* %49)
%52 = call i32 @fs_cp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %53
53: ; preds = %48, %45
%54 = call i32 @write_string_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%55 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%56 = call i32 @read_string_from_file(i8* %46, i8* %55, i32 41)
%57 = call i32 @checkout_commit(i8* %55)
br label %58
58: ; preds = %37, %42, %53, %30
%59 = phi i32 [ %31, %30 ], [ 1, %37 ], [ %57, %53 ], [ 1, %42 ]
ret i32 %59
}