#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 */
struct passwd {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ read_formats(char *, int *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
void read_global_formats(int *numformatsp) {
  struct passwd *pwd;
  char *homedir;
  char filename[4097];
  homedir = getenv("HOME");
  if (homedir == NULL && (pwd = getpwuid(getuid())) != NULL)
    homedir = pwd->pw_dir;
  if (homedir == NULL) {
    fprintf(stderr, ">W Can't find home directory\n");
    return;
  }
  sprintf(filename, "%s/sumlines.fmt", homedir);
  read_formats(filename, numformatsp, 0);
}


x86 assembly (clang, -O0):
<read_global_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b1 <read_global_formats+0x51>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11b1 <read_global_formats+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <read_global_formats+0x76>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ff <read_global_formats+0x9f>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1070 <read_formats@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_global_formats>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ab <read_global_formats+0x4b>
lea    0xe9e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <read_formats@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11c6 <read_global_formats+0x66>
mov    (%rax),%rax
test   %rax,%rax
jne    117e <read_global_formats+0x1e>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
add    $0x1008,%rsp
pop    %rbx
pop    %r14
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c">W Can't find home directory\0A\00"
@.str.2 = [16 x i8] c"%s/sumlines.fmt\00"
define void @read_global_formats(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.passwd*
%4 = alloca i8*
%5 = alloca [4097 x i8]
store i32* %0, i32** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = call i32 (...) @getuid()
%11 = call %struct.passwd* @getpwuid(i32 %10)
store %struct.passwd* %11, %struct.passwd** %3
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load %struct.passwd*, %struct.passwd** %3
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
store i8* %16, i8** %4
br label %17
17: ; preds = %13, %9, %1
%18 = load i8*, i8** %4
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %30
23: ; preds = %17
%24 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %4
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%28 = load i32*, i32** %2
%29 = call i32 @read_formats(i8* %27, i32* %28, i32 0)
br label %30
30: ; preds = %23, %20
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c">W Can't find home directory\0A\00"
@.str.2 = [16 x i8] c"%s/sumlines.fmt\00"
define void @read_global_formats(i32* %0) {
%2 = alloca [4097 x i8]
%3 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = tail call i32 (...) @getuid()
%8 = tail call %struct.passwd* @getpwuid(i32 %7)
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %6, %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %21
17: ; preds = %1, %10
%18 = phi i8* [ %12, %10 ], [ %4, %1 ]
%19 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 @read_formats(i8* %3, i32* %0, i32 0)
br label %21
21: ; preds = %17, %14
ret void
}