#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 */

/* Variables and functions */
int CHAR_BIT;
int abs(int);
scalar_t__ getchar();
int /*<<< orphan*/ printf(char *, int);
int dirseed(void) {
  int seed = 0;
  unsigned int i;
  unsigned char ch, b = 0;
  printf("%d random lines:\n", (int)(sizeof(int) / sizeof(char)));
  for (i = 0; i < sizeof(int); i++) {
    while ((ch = (unsigned char)getchar()) != '\n')
      b += ch;
    seed = (seed << CHAR_BIT) | (int)(b);
  }
  return abs(seed);
}


x86 assembly (clang, -O0):
<dirseed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0xa(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x4,%rax
jae    11ba <dirseed+0x8a>
jmp    116d <dirseed+0x3d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movzbl %al,%eax
cmp    $0xa,%eax
je     1195 <dirseed+0x65>
movzbl -0x9(%rbp),%ecx
movzbl -0xa(%rbp),%eax
add    %ecx,%eax
mov    %al,-0xa(%rbp)
jmp    116d <dirseed+0x3d>
mov    -0x4(%rbp),%eax
mov    0x2e41(%rip),%rcx
mov    (%rcx),%ecx
shl    %cl,%eax
movzbl -0xa(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <dirseed+0x2b>
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirseed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xece(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
xor    %ecx,%ecx
xchg   %ax,%ax
mov    %ecx,%r13d
xor    %eax,%eax
call   1040 <getchar@plt>
lea    (%rax,%r13,1),%ecx
cmp    $0xa,%al
jne    1140 <dirseed+0x20>
mov    %r13d,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
lea    (%rax,%rbp,1),%ecx
cmp    $0xa,%al
jne    1160 <dirseed+0x40>
mov    0x2e69(%rip),%r15
mov    (%r15),%r14d
mov    %ebp,%ecx
nopl   0x0(%rax)
mov    %ecx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
lea    (%rbx,%rax,1),%ecx
cmp    $0xa,%al
jne    1180 <dirseed+0x60>
mov    (%r15),%r15d
mov    %ebx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%r12d
xor    %eax,%eax
call   1040 <getchar@plt>
lea    (%r12,%rax,1),%ecx
cmp    $0xa,%al
jne    11a0 <dirseed+0x80>
movzbl %r13b,%eax
mov    %r14d,%ecx
shl    %cl,%eax
movzbl %bpl,%edx
or     %eax,%edx
mov    %r15d,%ecx
shl    %cl,%edx
movzbl %bl,%eax
or     %eax,%edx
mov    0x2e0e(%rip),%rax
mov    (%rax),%cl
shl    %cl,%edx
movzbl %r12b,%ecx
or     %edx,%ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%d random lines:\0A\00"
@CHAR_BIT = global i32 0
define i32 @dirseed() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
store i32 0, i32* %1
store i8 0, i8* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 4)
store i32 0, i32* %2
br label %6
6: ; preds = %30, %0
%7 = load i32, i32* %2
%8 = zext i32 %7 to i64
%9 = icmp ult i64 %8, 4
br i1 %9, label %10, label %33
10: ; preds = %6
br label %11
11: ; preds = %16, %10
%12 = call i64 (...) @getchar()
%13 = trunc i64 %12 to i8
store i8 %13, i8* %3
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = add nsw i32 %20, %18
%22 = trunc i32 %21 to i8
store i8 %22, i8* %4
br label %11
23: ; preds = %11
%24 = load i32, i32* %1
%25 = load i32, i32* @CHAR_BIT
%26 = shl i32 %24, %25
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = or i32 %26, %28
store i32 %29, i32* %1
br label %30
30: ; preds = %23
%31 = load i32, i32* %2
%32 = add i32 %31, 1
store i32 %32, i32* %2
br label %6
33: ; preds = %6
%34 = load i32, i32* %1
%35 = call i32 @abs(i32 %34)
ret i32 %35
}

LLVM IR (-O2):
@.str = [18 x i8] c"%d random lines:\0A\00"
@CHAR_BIT = global i32 0
define i32 @dirseed() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 4)
br label %2
2: ; preds = %2, %0
%3 = phi i8 [ %8, %2 ], [ 0, %0 ]
%4 = tail call i64 (...) @getchar()
%5 = and i64 %4, 255
%6 = icmp eq i64 %5, 10
%7 = trunc i64 %4 to i8
%8 = add i8 %3, %7
br i1 %6, label %9, label %2
9: ; preds = %2, %9
%10 = phi i8 [ %15, %9 ], [ %3, %2 ]
%11 = tail call i64 (...) @getchar()
%12 = and i64 %11, 255
%13 = icmp eq i64 %12, 10
%14 = trunc i64 %11 to i8
%15 = add i8 %10, %14
br i1 %13, label %16, label %9
16: ; preds = %9
%17 = load i32, i32* @CHAR_BIT
br label %18
18: ; preds = %18, %16
%19 = phi i8 [ %24, %18 ], [ %10, %16 ]
%20 = tail call i64 (...) @getchar()
%21 = and i64 %20, 255
%22 = icmp eq i64 %21, 10
%23 = trunc i64 %20 to i8
%24 = add i8 %19, %23
br i1 %22, label %25, label %18
25: ; preds = %18
%26 = load i32, i32* @CHAR_BIT
br label %27
27: ; preds = %27, %25
%28 = phi i8 [ %33, %27 ], [ %19, %25 ]
%29 = tail call i64 (...) @getchar()
%30 = and i64 %29, 255
%31 = icmp eq i64 %30, 10
%32 = trunc i64 %29 to i8
%33 = add i8 %28, %32
br i1 %31, label %34, label %27
34: ; preds = %27
%35 = zext i8 %19 to i32
%36 = zext i8 %3 to i32
%37 = shl i32 %36, %17
%38 = zext i8 %10 to i32
%39 = or i32 %37, %38
%40 = shl i32 %39, %26
%41 = or i32 %40, %35
%42 = load i32, i32* @CHAR_BIT
%43 = shl i32 %41, %42
%44 = zext i8 %28 to i32
%45 = or i32 %43, %44
%46 = tail call i32 @llvm.abs.i32(i32 %45, i1 true)
ret i32 %46
}