#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 /*<<< orphan*/ strncpy(char *, char *, int);
char *strsave(char *);
char *first(char *list) {
  char *s = strchr(list, ';');
  if (s) {
    char buf[1024];
    strncpy(buf, list, s - list);
    buf[s - list] = '\0';
    return strsave(buf);
  } else
    return list;
}


x86 assembly (clang, -O0):
<first>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a1 <first+0x71>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
call   1050 <strsave@plt>
mov    %rax,-0x8(%rbp)
jmp    11a9 <first+0x79>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1173 <first+0x43>
mov    %rax,%rbx
sub    %r14,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
call   1050 <strsave@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @first(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 59)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %28
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = load i8*, i8** %3
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @strncpy(i8* %11, i8* %12, i32 %18)
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = call i8* @strsave(i8* %26)
store i8* %27, i8** %2
br label %30
28: ; preds = %1
%29 = load i8*, i8** %3
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %10
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
define i8* @first(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 59)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = ptrtoint i8* %3 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = call i32 @strncpy(i8* %6, i8* %0, i32 %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %12
%13 = call i8* @strsave(i8* %6)
br label %14
14: ; preds = %1, %5
%15 = phi i8* [ %13, %5 ], [ %0, %1 ]
ret i8* %15
}