#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char const *);
int get_lineno();
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
void get_fieldname(const char *arg, char *fieldname) {
  char *pactual = strchr(arg, '|');
  char *pstart;
  if (pactual) {
    pactual++;
    pstart = strchr(pactual, '|');
    if (pstart) {
      pstart++;
      strncpy(fieldname, pstart, 128);
      return;
    }
  }
  fprintf(stderr, "%d: Missing union fieldname: %s\n", get_lineno(), arg);
  exit(15);
}


x86 assembly (clang, -O0):
<get_fieldname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cf <get_fieldname+0x7f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ca <get_fieldname+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
add    $0x30,%rsp
pop    %rbp
ret
jmp    11cf <get_fieldname+0x7f>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <get_lineno@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
lea    0xe0e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xf,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<get_fieldname>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x7c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119a <get_fieldname+0x4a>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119a <get_fieldname+0x4a>
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x80,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strncpy@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <get_lineno@plt>
lea    0xe4f(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    $0xf,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"%d: Missing union fieldname: %s\0A\00"
define void @get_fieldname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 124)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i8* @strchr(i8* %14, i8 signext 124)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
%21 = load i8*, i8** %4
%22 = load i8*, i8** %6
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 128)
ret void
24: ; preds = %11
br label %25
25: ; preds = %24, %2
%26 = load i32, i32* @stderr
%27 = call i32 (...) @get_lineno()
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %28)
%30 = call i32 @exit(i32 15)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"%d: Missing union fieldname: %s\0A\00"
define void @get_fieldname(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 124)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i8* @strchr(i8* %6, i8 signext 124)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i32 @strncpy(i8* %1, i8* %10, i32 128)
ret void
12: ; preds = %5, %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (...) @get_lineno()
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %0)
%16 = tail call i32 @exit(i32 15)
unreachable
}