#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 rpcent {
  unsigned int r_number;
};

/* Variables and functions */
struct rpcent *getrpcbyname(char const *);
int /*<<< orphan*/ log_fatal(char *, char const *);
unsigned int strtoul(char const *, char **, int /*<<< orphan*/);
unsigned int get_program(const char *name) {
  const char *end;
  unsigned int pnum;
  pnum = strtoul(name, (char **)&end, 0);
  if (*end != '\0') {
    struct rpcent *re;
    re = getrpcbyname(name);
    if (re != 0)
      pnum = re->r_number;
  }
  if (pnum == 0)
    log_fatal("Unable to parse RPC program name/number \"%s\"", name);
  return pnum;
}


x86 assembly (clang, -O0):
<get_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1184 <get_program+0x54>
mov    -0x8(%rbp),%rdi
call   1040 <getrpcbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117f <get_program+0x4f>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <get_program+0x54>
cmpl   $0x0,-0x14(%rbp)
jne    119e <get_program+0x6e>
mov    -0x8(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1050 <log_fatal@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_program>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,%ebp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     115a <get_program+0x2a>
mov    %rbx,%rdi
call   1040 <getrpcbyname@plt>
test   %rax,%rax
je     115a <get_program+0x2a>
mov    (%rax),%ebp
test   %ebp,%ebp
jne    116d <get_program+0x3d>
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <log_fatal@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rpcent = type { i32 }
@.str = [45 x i8] c"Unable to parse RPC program name/number \22%s\22\00"
define i32 @get_program(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.rpcent*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strtoul(i8* %6, i8** %3, i32 0)
store i32 %7, i32* %4
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call %struct.rpcent* @getrpcbyname(i8* %13)
store %struct.rpcent* %14, %struct.rpcent** %5
%15 = load %struct.rpcent*, %struct.rpcent** %5
%16 = icmp ne %struct.rpcent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load %struct.rpcent*, %struct.rpcent** %5
%19 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %18, i32 0, i32 0
%20 = load i32, i32* %19
store i32 %20, i32* %4
br label %21
21: ; preds = %17, %12
br label %22
22: ; preds = %21, %1
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %2
%27 = call i32 @log_fatal(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.rpcent = type { i32 }
@.str = [45 x i8] c"Unable to parse RPC program name/number \22%s\22\00"
define i32 @get_program(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @strtoul(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = tail call %struct.rpcent* @getrpcbyname(i8* %0)
%10 = icmp eq %struct.rpcent* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.rpcent, %struct.rpcent* %9, i64 0, i32 0
%13 = load i32, i32* %12
br label %14
14: ; preds = %8, %11, %1
%15 = phi i32 [ %4, %1 ], [ %13, %11 ], [ %4, %8 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @log_fatal(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %14
ret i32 %15
}