#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int,
                           char const *);
char *malloc(size_t);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
size_t strcspn(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *get_field(const char *line, unsigned n) {
  const char *semi;
  char *field = NULL;
  size_t length;
  unsigned i;
  for (i = 0, semi = line; i < n; i++, semi++) {
    if ((semi = strchr(semi, ';')) == NULL) {
      fprintf(stderr, "can't get field #%u from '%s'\n", n, line);
      break;
    }
  }
  length = strcspn(semi, ";");
  if ((field = malloc(length + 1)) == NULL) {
    perror(NULL);
    exit(EXIT_FAILURE);
  }
  strncpy(field, semi, length);
  field[length] = '\0';
  return field;
}


x86 assembly (clang, -O0):
<get_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11fe <get_field+0x8e>
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11df <get_field+0x6f>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11fe <get_field+0x8e>
jmp    11e4 <get_field+0x74>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1196 <get_field+0x26>
mov    -0x18(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1244 <get_field+0xd4>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %esi,%esi
je     11b0 <get_field+0x40>
mov    %esi,%r15d
mov    %esi,%ebp
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b5 <get_field+0x45>
mov    %rax,%rbx
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    1190 <get_field+0x20>
jmp    11d2 <get_field+0x62>
mov    %r14,%rbx
jmp    11d2 <get_field+0x62>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcspn@plt>
mov    %rax,%r14
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1217 <get_field+0xa7>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%rbp,%r14,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1080 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"can't get field #%u from '%s'\0A\00"
@.str.1 = [2 x i8] c";\00"
@EXIT_FAILURE = global i32 0
define i8* @get_field(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %6
store i32 0, i32* %8
%9 = load i8*, i8** %3
store i8* %9, i8** %5
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = call i8* @strchr(i8* %15, i8 signext 59)
store i8* %16, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* %4
%21 = load i8*, i8** %3
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
br label %29
23: ; preds = %14
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = add i32 %25, 1
store i32 %26, i32* %8
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %10
29: ; preds = %18, %10
%30 = load i8*, i8** %5
%31 = call i64 @strcspn(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i64 %31, i64* %7
%32 = load i64, i64* %7
%33 = add i64 %32, 1
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %6
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = call i32 @perror(i32* null)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %29
%41 = load i8*, i8** %6
%42 = load i8*, i8** %5
%43 = load i64, i64* %7
%44 = call i32 @strncpy(i8* %41, i8* %42, i64 %43)
%45 = load i8*, i8** %6
%46 = load i64, i64* %7
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %6
ret i8* %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"can't get field #%u from '%s'\0A\00"
@.str.1 = [2 x i8] c";\00"
@EXIT_FAILURE = global i32 0
define i8* @get_field(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2, %12
%5 = phi i32 [ %13, %12 ], [ 0, %2 ]
%6 = phi i8* [ %14, %12 ], [ %0, %2 ]
%7 = tail call i8* @strchr(i8* dereferenceable(1) %6, i8 signext 59)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %0)
br label %16
12: ; preds = %4
%13 = add nuw i32 %5, 1
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = icmp eq i32 %13, %1
br i1 %15, label %16, label %4
16: ; preds = %12, %2, %9
%17 = phi i8* [ null, %9 ], [ %0, %2 ], [ %14, %12 ]
%18 = tail call i64 @strcspn(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = add i64 %18, 1
%20 = tail call i8* @malloc(i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = tail call i32 @perror(i32* null)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = tail call i32 @strncpy(i8* %20, i8* %17, i64 %18)
%28 = getelementptr inbounds i8, i8* %20, i64 %18
store i8 0, i8* %28
ret i8* %20
}