#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 */
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)
    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     1142 <getfield+0x22>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef6(%rip)
cmpq   $0x0,0x2eee(%rip)
jne    115d <getfield+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <getfield+0xd2>
mov    0x2ed4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ec9(%rip),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d4 <getfield+0xb4>
movq   $0x0,0x2ea6(%rip)
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cf <getfield+0xaf>
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    11e3 <getfield+0xc3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e55(%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    1135 <getfield+0x15>
mov    0x2f08(%rip),%rbx
test   %rbx,%rbx
je     1189 <getfield+0x69>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1157 <getfield+0x37>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2ee3(%rip)
jmp    1181 <getfield+0x61>
movq   $0x0,0x2ed6(%rip)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1181 <getfield+0x61>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret
xor    %ebx,%ebx
jmp    1184 <getfield+0x64>

LLVM IR (-O0):
@getfield.line = internal global i8* null
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 %14
13: ; preds = %10
store i8* null, i8** %2
br label %36
14: ; preds = %10
%15 = load i8*, i8** @getfield.line
store i8* %15, i8** %5
%16 = load i8*, i8** @getfield.line
%17 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %17, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %30
19: ; preds = %14
store i8* null, i8** @getfield.line
%20 = load i8*, i8** %5
%21 = call i8* @strchr(i8* %20, i8 signext 10)
store i8* %21, i8** %4
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8* %28, i8** %4
br label %29
29: ; preds = %23, %19
br label %33
30: ; preds = %14
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** @getfield.line
br label %33
33: ; preds = %30, %29
%34 = load i8*, i8** %4
store i8 0, i8* %34
%35 = load i8*, i8** %5
store i8* %35, i8** %2
br label %36
36: ; preds = %33, %13
%37 = load i8*, i8** %2
ret i8* %37
}

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