#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlen(char *);
char *getfield(char *newline) {
  static char *line = NULL;
  char *end, *field;
  if (newline)
    line = newline;
  if (line == NULL) {
    fprintf(stderr, "returned null!\n");
    return NULL;
  }
  field = line;
  if ((end = strchr(line, ':')) == NULL) {
    line = NULL;
    if ((end = strchr(field, '\n')) == NULL)
      end = field + strlen(field);
  } else
    line = end + 1;
  *end = '\0';
  return field;
}


x86 assembly (clang, -O0):
<getfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <getfield+0x22>
mov    -0x10(%rbp),%rax
mov    %rax,0x2eee(%rip)
cmpq   $0x0,0x2ee6(%rip)
jne    1182 <getfield+0x52>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1217 <getfield+0xe7>
mov    0x2eb7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2eac(%rip),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f9 <getfield+0xc9>
movq   $0x0,0x2e89(%rip)
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f4 <getfield+0xc4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1208 <getfield+0xd8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e38(%rip)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfield>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1145 <getfield+0x15>
mov    0x2f00(%rip),%rbx
test   %rbx,%rbx
je     1199 <getfield+0x69>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1167 <getfield+0x37>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2edb(%rip)
jmp    1191 <getfield+0x61>
movq   $0x0,0x2ece(%rip)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1191 <getfield+0x61>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    1194 <getfield+0x64>

LLVM IR (-O0):
@getfield.line = internal global i8* null
@stderr = global i32 0
@.str = [16 x i8] c"returned null!\0A\00"
define i8* @getfield(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %3
store i8* %9, i8** @getfield.line
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** @getfield.line
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %38
16: ; preds = %10
%17 = load i8*, i8** @getfield.line
store i8* %17, i8** %5
%18 = load i8*, i8** @getfield.line
%19 = call i8* @strchr(i8* %18, i8 signext 58)
store i8* %19, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %32
21: ; preds = %16
store i8* null, i8** @getfield.line
%22 = load i8*, i8** %5
%23 = call i8* @strchr(i8* %22, i8 signext 10)
store i8* %23, i8** %4
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8* %30, i8** %4
br label %31
31: ; preds = %25, %21
br label %35
32: ; preds = %16
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** @getfield.line
br label %35
35: ; preds = %32, %31
%36 = load i8*, i8** %4
store i8 0, i8* %36
%37 = load i8*, i8** %5
store i8* %37, i8** %2
br label %38
38: ; preds = %35, %13
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@getfield.line = internal unnamed_addr global i8* null
@stderr = global i32 0
@.str = [16 x i8] c"returned null!\0A\00"
define i8* @getfield(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = load i8*, i8** @getfield.line
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %24
9: ; preds = %1, %3
%10 = phi i8* [ %4, %3 ], [ %0, %1 ]
%11 = tail call i8* @strchr(i8* %10, i8 signext 58)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %9
store i8* null, i8** @getfield.line
%14 = tail call i8* @strchr(i8* %10, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %10)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
br label %22
20: ; preds = %9
%21 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %21, i8** @getfield.line
br label %22
22: ; preds = %13, %16, %20
%23 = phi i8* [ %19, %16 ], [ %14, %13 ], [ %11, %20 ]
store i8 0, i8* %23
br label %24
24: ; preds = %22, %6
%25 = phi i8* [ null, %6 ], [ %10, %22 ]
ret i8* %25
}