#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 protoent {
  int p_proto;
};

/* Variables and functions */
int _protoid_error(char const *, int);
struct protoent *getprotobyname(char const *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setprotoent(int);
int _protoid(char const *name) {
  struct protoent *pe;
  setprotoent(1);
  if ((pe = getprotobyname(name)) == NULL)
    return _protoid_error(name, 1);
  printf("%d\n", pe->p_proto);
  return 0;
}


x86 assembly (clang, -O0):
<_protoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <setprotoent@plt>
mov    -0x10(%rbp),%rdi
call   1060 <getprotobyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1183 <_protoid+0x43>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <_protoid_error@plt>
mov    %eax,-0x4(%rbp)
jmp    119c <_protoid+0x5c>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_protoid>:
push   %rbx
mov    %rdi,%rbx
mov    $0x1,%edi
call   1040 <setprotoent@plt>
mov    %rbx,%rdi
call   1060 <getprotobyname@plt>
test   %rax,%rax
je     116d <_protoid+0x2d>
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x1,%esi
pop    %rbx
jmp    1050 <_protoid_error@plt>

LLVM IR (-O0):
%struct.protoent = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @_protoid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.protoent*
store i8* %0, i8** %3
%5 = call i32 @setprotoent(i32 1)
%6 = load i8*, i8** %3
%7 = call %struct.protoent* @getprotobyname(i8* %6)
store %struct.protoent* %7, %struct.protoent** %4
%8 = icmp eq %struct.protoent* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @_protoid_error(i8* %10, i32 1)
store i32 %11, i32* %2
br label %17
12: ; preds = %1
%13 = load %struct.protoent*, %struct.protoent** %4
%14 = getelementptr inbounds %struct.protoent, %struct.protoent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 0, i32* %2
br label %17
17: ; preds = %12, %9
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.protoent = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @_protoid(i8* %0) {
%2 = tail call i32 @setprotoent(i32 1)
%3 = tail call %struct.protoent* @getprotobyname(i8* %0)
%4 = icmp eq %struct.protoent* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @_protoid_error(i8* %0, i32 1)
br label %11
7: ; preds = %1
%8 = getelementptr inbounds %struct.protoent, %struct.protoent* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %5
%12 = phi i32 [ %6, %5 ], [ 0, %7 ]
ret i32 %12
}