#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 */
typedef int /*<<< orphan*/ u_long;

/* Variables and functions */
int IPPROTO_TCP;
int IPPROTO_UDP;
int sscanf(char *, char *, int *, ...);
scalar_t__ strcmp(char *, char *);
int parse_line(char *buf, u_long *prog, u_long *vers, int *prot,
               unsigned *port) {
  char proto_name[256];
  if (sscanf(buf, "%lu %lu %255s %u", prog, vers, proto_name, port) != 4) {
    return (0);
  }
  if (strcmp(proto_name, "tcp") == 0) {
    *prot = IPPROTO_TCP;
    return (1);
  }
  if (strcmp(proto_name, "udp") == 0) {
    *prot = IPPROTO_UDP;
    return (1);
  }
  if (sscanf(proto_name, "%d", prot) == 1) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x130(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
cmp    $0x4,%eax
je     1179 <parse_line+0x59>
movl   $0x0,-0x4(%rbp)
jmp    121e <parse_line+0xfe>
lea    -0x130(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11b1 <parse_line+0x91>
mov    0x2e4b(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    121e <parse_line+0xfe>
lea    -0x130(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11e9 <parse_line+0xc9>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    121e <parse_line+0xfe>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1217 <parse_line+0xf7>
movl   $0x1,-0x4(%rbp)
jmp    121e <parse_line+0xfe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %r8,%r9
mov    %rcx,%rbx
mov    %rdx,%rcx
mov    %rsi,%rdx
lea    0xec4(%rip),%rsi
xor    %ebp,%ebp
mov    %rsp,%r8
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jne    11ad <parse_line+0x8d>
lea    0xebd(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1194 <parse_line+0x74>
lea    0xead(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     119d <parse_line+0x7d>
lea    0xe9d(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
jmp    11ad <parse_line+0x8d>
mov    0x2e4d(%rip),%rax
jmp    11a4 <parse_line+0x84>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%lu %lu %255s %u\00"
@.str.1 = [4 x i8] c"tcp\00"
@IPPROTO_TCP = global i32 0
@.str.2 = [4 x i8] c"udp\00"
@IPPROTO_UDP = global i32 0
@.str.3 = [3 x i8] c"%d\00"
define i32 @parse_line(i8* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [256 x i8]
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%13 = load i8*, i8** %7
%14 = load i32*, i32** %8
%15 = load i32*, i32** %9
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%17 = load i32*, i32** %11
%18 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %14, i32* %15, i8* %16, i32* %17)
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 0, i32* %6
br label %42
21: ; preds = %5
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @IPPROTO_TCP
%27 = load i32*, i32** %10
store i32 %26, i32* %27
store i32 1, i32* %6
br label %42
28: ; preds = %21
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @IPPROTO_UDP
%34 = load i32*, i32** %10
store i32 %33, i32* %34
store i32 1, i32* %6
br label %42
35: ; preds = %28
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%37 = load i32*, i32** %10
%38 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %37)
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %6
br label %42
41: ; preds = %35
store i32 0, i32* %6
br label %42
42: ; preds = %41, %40, %32, %25, %20
%43 = load i32, i32* %6
ret i32 %43
}

LLVM IR (-O2):
@.str = [17 x i8] c"%lu %lu %255s %u\00"
@.str.1 = [4 x i8] c"tcp\00"
@IPPROTO_TCP = global i32 0
@.str.2 = [4 x i8] c"udp\00"
@IPPROTO_UDP = global i32 0
@.str.3 = [3 x i8] c"%d\00"
define i32 @parse_line(i8* nocapture %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i8* %7, i32* %4)
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %24
10: ; preds = %5
%11 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* @IPPROTO_TCP
store i32 %14, i32* %3
br label %24
15: ; preds = %10
%16 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* @IPPROTO_UDP
store i32 %19, i32* %3
br label %24
20: ; preds = %15
%21 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %5, %18, %13
%25 = phi i32 [ 1, %13 ], [ 1, %18 ], [ 0, %5 ], [ %23, %20 ]
ret i32 %25
}