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

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
int /*<<< orphan*/ util_hex_dump(char *, char *, int);
int main(int argc, char *argv[]) {
  char *p;
  uint8_t buf[0x100];
  while (1) {
    printf(": ");
    p = fgets(buf, sizeof(buf), stdin);
    if (p == NULL) {
      break;
    }
    util_hex_dump("buf", buf, sizeof(buf));
    printf("%d: %s\n", (int)strlen(buf), buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <main+0x55>
jmp    11d5 <main+0x95>
lea    -0x120(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x100,%edx
call   1060 <util_hex_dump@plt>
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1159 <main+0x19>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e83(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11e7 <main+0xa7>
lea    0xe81(%rip),%r14
mov    %rsp,%rbx
lea    0xe7b(%rip),%r15
lea    0xe6d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <util_hex_dump@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c": \00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"buf\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %16
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i8* @fgets(i8* %10, i32 256, i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %8
br label %24
16: ; preds = %8
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = call i32 @util_hex_dump(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 256)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %21, i8* %22)
br label %8
24: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c": \00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"buf\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i8* @fgets(i8* %4, i32 256, i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %2, %9
%10 = call i32 @util_hex_dump(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 256)
%11 = call i64 @strlen(i8* %4)
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stdin
%16 = call i8* @fgets(i8* %4, i32 256, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %2
ret i32 0
}