#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dump_proto(struct protoent *);
struct protoent *getprotobynumber(int);
int /*<<< orphan*/ printf(char *, int);
void test_proto3(int num) {
  struct protoent *h = getprotobynumber(num);
  if (h) {
    printf("find protocol by number: %d\n", num);
    dump_proto(h);
  } else
    printf("no protocol found by number: %d\n", num);
}


x86 assembly (clang, -O0):
<test_proto3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getprotobynumber@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116f <test_proto3+0x3f>
mov    -0x4(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <dump_proto@plt>
jmp    117e <test_proto3+0x4e>
mov    -0x4(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_proto3>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <getprotobynumber@plt>
test   %rax,%rax
je     1160 <test_proto3+0x30>
mov    %rax,%r14
lea    0xeb6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <dump_proto@plt>
lea    0xeb6(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.protoent = type { i32 }
@.str = [29 x i8] c"find protocol by number: %d\0A\00"
@.str.1 = [33 x i8] c"no protocol found by number: %d\0A\00"
define void @test_proto3(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.protoent*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call %struct.protoent* @getprotobynumber(i32 %4)
store %struct.protoent* %5, %struct.protoent** %3
%6 = load %struct.protoent*, %struct.protoent** %3
%7 = icmp ne %struct.protoent* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load %struct.protoent*, %struct.protoent** %3
%12 = call i32 @dump_proto(%struct.protoent* %11)
br label %16
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %8
ret void
}

LLVM IR (-O2):
%struct.protoent = type { i32 }
@.str = [29 x i8] c"find protocol by number: %d\0A\00"
@.str.1 = [33 x i8] c"no protocol found by number: %d\0A\00"
define void @test_proto3(i32 %0) {
%2 = tail call %struct.protoent* @getprotobynumber(i32 %0)
%3 = icmp eq %struct.protoent* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = tail call i32 @dump_proto(%struct.protoent* %2)
br label %9
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %7, %4
ret void
}