#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*/ time_t;
struct chirp_client {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EINVAL;
struct chirp_client *chirp_client_connect(char *, int /*<<< orphan*/,
                                          int /*<<< orphan*/);
int chirp_client_cookie(struct chirp_client *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ chirp_client_disconnect(struct chirp_client *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
struct chirp_client *chirp_client_connect_condor(time_t stoptime) {
  FILE *file;
  int fields;
  int save_errno;
  struct chirp_client *client;
  char host[1024];
  char hostport[1024];
  char cookie[1024];
  int port;
  int result;
  file = fopen("chirp.config", "r");
  if (!file)
    file = fopen(".chirp.config", "r");
  if (!file)
    file = fopen(".chirp_config", "r");
  if (!file)
    return 0;
  fields = fscanf(file, "%s %d %s", host, &port, cookie);
  fclose(file);
  if (fields != 3) {
    errno = EINVAL;
    return 0;
  }
  sprintf(hostport, "%s:%d", host, port);
  client = chirp_client_connect(hostport, 0, stoptime);
  if (!client)
    return 0;
  result = chirp_client_cookie(client, cookie, stoptime);
  if (result != 0) {
    save_errno = errno;
    chirp_client_disconnect(client);
    errno = save_errno;
    return 0;
  }
  return client;
}


x86 assembly (clang, -O0):
<chirp_client_connect_condor>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc40,%rsp
mov    %edi,-0xc(%rbp)
lea    0xe7e(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <chirp_client_connect_condor+0x47>
lea    0xe5b(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d9 <chirp_client_connect_condor+0x69>
lea    0xe47(%rip),%rdi
lea    0xe30(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <chirp_client_connect_condor+0x81>
movq   $0x0,-0x8(%rbp)
jmp    12f4 <chirp_client_connect_condor+0x184>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    -0xc30(%rbp),%r8
lea    0xe14(%rip),%rsi
lea    -0xc34(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x3,-0x1c(%rbp)
je     124b <chirp_client_connect_condor+0xdb>
mov    0x2da5(%rip),%rax
mov    (%rax),%ecx
mov    0x2da4(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    12f4 <chirp_client_connect_condor+0x184>
lea    -0x830(%rbp),%rdi
lea    -0x430(%rbp),%rdx
mov    -0xc34(%rbp),%ecx
lea    0xdc1(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x830(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1060 <chirp_client_connect@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1298 <chirp_client_connect_condor+0x128>
movq   $0x0,-0x8(%rbp)
jmp    12f4 <chirp_client_connect_condor+0x184>
mov    -0x28(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1090 <chirp_client_cookie@plt>
mov    %eax,-0xc38(%rbp)
cmpl   $0x0,-0xc38(%rbp)
je     12ec <chirp_client_connect_condor+0x17c>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <chirp_client_disconnect@plt>
mov    -0x20(%rbp),%ecx
mov    0x2d03(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    12f4 <chirp_client_connect_condor+0x184>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chirp_client_connect_condor>:
push   %rbp
push   %r14
push   %rbx
sub    $0xc10,%rsp
mov    %edi,%r14d
lea    0xe7e(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d3 <chirp_client_connect_condor+0x63>
lea    0xe62(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d3 <chirp_client_connect_condor+0x63>
lea    0xe55(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1274 <chirp_client_connect_condor+0x104>
lea    0xe44(%rip),%rsi
lea    0x410(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x3,%ebp
jne    1262 <chirp_client_connect_condor+0xf2>
mov    0xc(%rsp),%ecx
lea    0xe19(%rip),%rsi
lea    0x810(%rsp),%rbx
lea    0x410(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1060 <chirp_client_connect@plt>
test   %rax,%rax
je     1274 <chirp_client_connect_condor+0x104>
mov    %rax,%rbx
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1090 <chirp_client_cookie@plt>
test   %eax,%eax
je     1276 <chirp_client_connect_condor+0x106>
mov    0x2d8a(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <chirp_client_disconnect@plt>
jmp    126b <chirp_client_connect_condor+0xfb>
mov    0x2d6f(%rip),%rax
mov    (%rax),%ebp
mov    0x2d6e(%rip),%rax
mov    %ebp,(%rax)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0xc10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.chirp_client = type { i32 }
@.str = [13 x i8] c"chirp.config\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c".chirp.config\00"
@.str.3 = [14 x i8] c".chirp_config\00"
@.str.4 = [9 x i8] c"%s %d %s\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str.5 = [6 x i8] c"%s:%d\00"
define %struct.chirp_client* @chirp_client_connect_condor(i32 %0) {
%2 = alloca %struct.chirp_client*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.chirp_client*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
%13 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %4
br label %18
18: ; preds = %16, %1
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %4
br label %23
23: ; preds = %21, %18
%24 = load i32*, i32** %4
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store %struct.chirp_client* null, %struct.chirp_client** %2
br label %63
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = call i32 @fscanf(i32* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %29, i32* %11, i8* %30)
store i32 %31, i32* %5
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 3
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = load i32, i32* @EINVAL
store i32 %37, i32* @errno
store %struct.chirp_client* null, %struct.chirp_client** %2
br label %63
38: ; preds = %27
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %11
%42 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %40, i32 %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = load i32, i32* %3
%45 = call %struct.chirp_client* @chirp_client_connect(i8* %43, i32 0, i32 %44)
store %struct.chirp_client* %45, %struct.chirp_client** %7
%46 = load %struct.chirp_client*, %struct.chirp_client** %7
%47 = icmp ne %struct.chirp_client* %46, null
br i1 %47, label %49, label %48
48: ; preds = %38
store %struct.chirp_client* null, %struct.chirp_client** %2
br label %63
49: ; preds = %38
%50 = load %struct.chirp_client*, %struct.chirp_client** %7
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = load i32, i32* %3
%53 = call i32 @chirp_client_cookie(%struct.chirp_client* %50, i8* %51, i32 %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %49
%57 = load i32, i32* @errno
store i32 %57, i32* %6
%58 = load %struct.chirp_client*, %struct.chirp_client** %7
%59 = call i32 @chirp_client_disconnect(%struct.chirp_client* %58)
%60 = load i32, i32* %6
store i32 %60, i32* @errno
store %struct.chirp_client* null, %struct.chirp_client** %2
br label %63
61: ; preds = %49
%62 = load %struct.chirp_client*, %struct.chirp_client** %7
store %struct.chirp_client* %62, %struct.chirp_client** %2
br label %63
63: ; preds = %61, %56, %48, %36, %26
%64 = load %struct.chirp_client*, %struct.chirp_client** %2
ret %struct.chirp_client* %64
}

LLVM IR (-O2):
%struct.chirp_client = type { i32 }
@.str = [13 x i8] c"chirp.config\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c".chirp.config\00"
@.str.3 = [14 x i8] c".chirp_config\00"
@.str.4 = [9 x i8] c"%s %d %s\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str.5 = [6 x i8] c"%s:%d\00"
define %struct.chirp_client* @chirp_client_connect_condor(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %38, label %18
18: ; preds = %1, %12, %15
%19 = phi i32* [ %16, %15 ], [ %13, %12 ], [ %10, %1 ]
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32* %5, i8* %8)
%21 = call i32 @fclose(i32* %19)
%22 = icmp eq i32 %20, 3
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = load i32, i32* @EINVAL
br label %36
25: ; preds = %18
%26 = load i32, i32* %5
%27 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 %26)
%28 = call %struct.chirp_client* @chirp_client_connect(i8* %7, i32 0, i32 %0)
%29 = icmp eq %struct.chirp_client* %28, null
br i1 %29, label %38, label %30
30: ; preds = %25
%31 = call i32 @chirp_client_cookie(%struct.chirp_client* %28, i8* %8, i32 %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = load i32, i32* @errno
%35 = call i32 @chirp_client_disconnect(%struct.chirp_client* %28)
br label %36
36: ; preds = %23, %33
%37 = phi i32 [ %34, %33 ], [ %24, %23 ]
store i32 %37, i32* @errno
br label %38
38: ; preds = %36, %30, %25, %15
%39 = phi %struct.chirp_client* [ null, %15 ], [ null, %25 ], [ %28, %30 ], [ null, %36 ]
ret %struct.chirp_client* %39
}