#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 ip_usbph {
  int dummy;
};
typedef int /*<<< orphan*/ rcfile;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
char *getenv(char *);
int /*<<< orphan*/ ip_usbph_state_load(struct ip_usbph *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void rc_load(struct ip_usbph *ph) {
  char rcfile[PATH_MAX];
  int fd;
  snprintf(rcfile, sizeof(rcfile), "%s/.ip-usbphrc", getenv("HOME"));
  fd = open(rcfile, O_RDONLY);
  if (fd >= 0) {
    ip_usbph_state_load(ph, fd);
    close(fd);
  }
}


x86 assembly (clang, -O0):
<rc_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    %eax,-0x2c(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
lea    0xe58(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11e0 <rc_load+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <ip_usbph_state_load@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_load>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e8c(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe72(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11c4 <rc_load+0x74>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <ip_usbph_state_load@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_usbph = type { i32 }
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/.ip-usbphrc\00"
@.str.1 = [5 x i8] c"HOME\00"
@O_RDONLY = global i32 0
define void @rc_load(%struct.ip_usbph* %0) {
%2 = alloca %struct.ip_usbph*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store %struct.ip_usbph* %0, %struct.ip_usbph** %2
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca i8, i64 %7
store i64 %7, i64* %4
%10 = trunc i64 %7 to i32
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @snprintf(i8* %9, i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %9, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %1
%18 = load %struct.ip_usbph*, %struct.ip_usbph** %2
%19 = load i32, i32* %5
%20 = call i32 @ip_usbph_state_load(%struct.ip_usbph* %18, i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %17, %1
%24 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
%struct.ip_usbph = type { i32 }
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/.ip-usbphrc\00"
@.str.1 = [5 x i8] c"HOME\00"
@O_RDONLY = global i32 0
define void @rc_load(%struct.ip_usbph* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @snprintf(i8* %4, i32 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %4, i32 %7)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @ip_usbph_state_load(%struct.ip_usbph* %0, i32 %8)
%12 = call i32 @close(i32 %8)
br label %13
13: ; preds = %10, %1
ret void
}