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

/* Variables and functions */
int BUFSIZ;
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ parse_line(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *, int *,
                      unsigned int *);
scalar_t__ pmap_set(int /*<<< orphan*/, int /*<<< orphan*/, int,
                    unsigned short);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buf[BUFSIZ];
  u_long prog;
  u_long vers;
  int prot;
  unsigned port;
  while (fgets(buf, sizeof(buf), stdin)) {
    if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
      fprintf(stderr, "%s: malformed line: %s", argv[0], buf);
      return (1);
    }
    if (pmap_set(prog, vers, prot, (unsigned short)port) == 0)
      fprintf(stderr, "not registered: %s", buf);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     123e <main+0xfe>
mov    -0x40(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1050 <parse_line@plt>
cmp    $0x0,%rax
jne    1200 <main+0xc0>
mov    -0x40(%rbp),%rcx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    124c <main+0x10c>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%eax
movzwl %ax,%ecx
call   1060 <pmap_set@plt>
cmp    $0x0,%rax
jne    1239 <main+0xf9>
mov    -0x40(%rbp),%rdx
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1186 <main+0x46>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    0x2e75(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1206 <main+0xc6>
mov    %r14,-0x40(%rbp)
lea    -0x34(%rbp),%r13
lea    -0x30(%rbp),%r14
lea    -0x2c(%rbp),%r12
jmp    11b9 <main+0x79>
nopl   (%rax)
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1206 <main+0xc6>
mov    %rbx,%rdi
lea    -0x38(%rbp),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1050 <parse_line@plt>
test   %rax,%rax
je     120a <main+0xca>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
movzwl -0x2c(%rbp),%ecx
call   1060 <pmap_set@plt>
test   %rax,%rax
jne    11a0 <main+0x60>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11a0 <main+0x60>
xor    %eax,%eax
jmp    1230 <main+0xf0>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%rdx
lea    0xddf(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: malformed line: %s\00"
@.str.1 = [19 x i8] c"not registered: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
br label %17
17: ; preds = %42, %2
%18 = trunc i64 %14 to i32
%19 = load i32, i32* @stdin
%20 = call i64 @fgets(i8* %16, i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = call i64 @parse_line(i8* %16, i32* %8, i32* %9, i32* %10, i32* %11)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %16)
store i32 1, i32* %3
store i32 1, i32* %12
br label %44
31: ; preds = %22
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = load i32, i32* %11
%36 = trunc i32 %35 to i16
%37 = call i64 @pmap_set(i32 %32, i32 %33, i32 %34, i16 zeroext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %42
42: ; preds = %39, %31
br label %17
43: ; preds = %17
store i32 0, i32* %3
store i32 1, i32* %12
br label %44
44: ; preds = %43, %25
%45 = load i8*, i8** %6
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: malformed line: %s\00"
@.str.1 = [19 x i8] c"not registered: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = load i32, i32* @stdin
%15 = call i64 @fgets(i8* %9, i32 %7, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %2, %35
%18 = call i64 @parse_line(i8* %9, i32* %3, i32* %4, i32* %5, i32* %6)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %9)
br label %39
24: ; preds = %17
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = trunc i32 %28 to i16
%30 = call i64 @pmap_set(i32 %25, i32 %26, i32 %27, i16 zeroext %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %35
35: ; preds = %32, %24
%36 = load i32, i32* @stdin
%37 = call i64 @fgets(i8* %9, i32 %7, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %17
39: ; preds = %35, %2, %20
%40 = phi i32 [ 1, %20 ], [ 0, %2 ], [ 0, %35 ]
ret i32 %40
}