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

/* Variables and functions */
int /*<<< orphan*/ EX_DATAERR;
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ EX_USAGE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ forward_through_gateway(int, char **);
scalar_t__ getenv(char *);
int gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ run_shell(int, char **);
int /*<<< orphan*/ serve_data(int, char **);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char host[1024];
  char *c;
  if (gethostname(host, sizeof(host)) == -1) {
    perror("gethostname");
    exit(EX_OSERR);
  }
  if ((c = strchr(host, '.')) != NULL) {
    *c = '\0';
  }
  if (getenv("SSH_CLIENT")) {
    char *hg_gateway = "gateway";
    char *hg_host = "mercurial";
    if (hg_gateway && strcmp(host, hg_gateway) == 0) {
      forward_through_gateway(argc, argv);
    }
    if (hg_host && strcmp(host, hg_host) != 0) {
      usage("invoked on unexpected host", EX_USAGE);
    }
    serve_data(argc, argv);
  } else if (NULL) {
    run_shell(argc, argv);
  } else {
    usage("invalid arguments", EX_DATAERR);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    11ed <main+0x4d>
lea    0xe26(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x410(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     1219 <main+0x79>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
lea    0xdec(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12d3 <main+0x133>
lea    0xde1(%rip),%rax
mov    %rax,-0x420(%rbp)
lea    0xddb(%rip),%rax
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     1282 <main+0xe2>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1282 <main+0xe2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <forward_through_gateway@plt>
cmpq   $0x0,-0x428(%rbp)
je     12c2 <main+0x122>
lea    -0x410(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12c2 <main+0x122>
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    0xd6c(%rip),%rdi
call   1090 <usage@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <serve_data@plt>
jmp    130d <main+0x16d>
xor    %eax,%eax
test   $0x1,%al
jne    12e2 <main+0x142>
jmp    12f3 <main+0x153>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <run_shell@plt>
jmp    1308 <main+0x168>
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
lea    0xd41(%rip),%rdi
call   1090 <usage@plt>
jmp    130d <main+0x16d>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x400,%esi
call   10a0 <gethostname@plt>
cmp    $0xffffffff,%eax
je     124e <main+0xbe>
mov    %rsp,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c9 <main+0x39>
movb   $0x0,(%rax)
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     122d <main+0x9d>
lea    0xe36(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f8 <main+0x68>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <forward_through_gateway@plt>
lea    0xe20(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1221 <main+0x91>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe0d(%rip),%rdi
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <serve_data@plt>
jmp    1242 <main+0xb2>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   1080 <usage@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdab(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"gethostname\00"
@EX_OSERR = global i32 0
@.str.1 = [11 x i8] c"SSH_CLIENT\00"
@.str.2 = [8 x i8] c"gateway\00"
@.str.3 = [10 x i8] c"mercurial\00"
@.str.4 = [27 x i8] c"invoked on unexpected host\00"
@EX_USAGE = global i32 0
@.str.5 = [18 x i8] c"invalid arguments\00"
@EX_DATAERR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 1024)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EX_OSERR
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i8* @strchr(i8* %18, i8 signext 46)
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i8*, i8** %7
store i8 0, i8* %22
br label %23
23: ; preds = %21, %17
%24 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %53
26: ; preds = %23
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %9
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = load i8*, i8** %8
%32 = call i64 @strcmp(i8* %30, i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %4
%36 = load i8**, i8*** %5
%37 = call i32 @forward_through_gateway(i32 %35, i8** %36)
br label %38
38: ; preds = %34, %29, %26
%39 = load i8*, i8** %9
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%43 = load i8*, i8** %9
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* @EX_USAGE
%48 = call i32 @usage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %41, %38
%50 = load i32, i32* %4
%51 = load i8**, i8*** %5
%52 = call i32 @serve_data(i32 %50, i8** %51)
br label %62
53: ; preds = %23
br i1 false, label %54, label %58
54: ; preds = %53
%55 = load i32, i32* %4
%56 = load i8**, i8*** %5
%57 = call i32 @run_shell(i32 %55, i8** %56)
br label %61
58: ; preds = %53
%59 = load i32, i32* @EX_DATAERR
%60 = call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %54
br label %62
62: ; preds = %61, %49
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"gethostname\00"
@EX_OSERR = global i32 0
@.str.1 = [11 x i8] c"SSH_CLIENT\00"
@.str.2 = [8 x i8] c"gateway\00"
@.str.3 = [10 x i8] c"mercurial\00"
@.str.4 = [27 x i8] c"invoked on unexpected host\00"
@EX_USAGE = global i32 0
@.str.5 = [18 x i8] c"invalid arguments\00"
@EX_DATAERR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @gethostname(i8* %4, i32 1024)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EX_OSERR
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = call i8* @strchr(i8* %4, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11
store i8 0, i8* %12
br label %15
15: ; preds = %14, %11
%16 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @forward_through_gateway(i32 %0, i8** %1)
br label %23
23: ; preds = %18, %21
%24 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @EX_USAGE
%28 = call i32 @usage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %23
%30 = call i32 @serve_data(i32 %0, i8** %1)
br label %34
31: ; preds = %15
%32 = load i32, i32* @EX_DATAERR
%33 = call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %29
ret i32 0
}