#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 EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char const *, char *, char *, int *);
int main(void) {
  const char str[] = "1982/08/12 21:30:37;data1;data2;data3;data4";
  const char *ptr = str;
  char field[20];
  int n, i;
  const char str2[] = "b3h3m0th:x:1000:1000:,,,:/home/b3h3m0th:/usr/bin/zsh";
  const char *ptr2 = str2;
  char *field2 = (char *)malloc(sizeof(15));
  int n2;
  i = 1;
  printf("Full string: %s\n", str);
  while (sscanf(ptr, "%19[^;]%n", field, &n) == 1) {
    printf("%d field = %s (%d byte)\n", i, field, n);
    ptr += n;
    if (*ptr != ';')
      break;
    ++ptr, i++;
  }
  i = 1;
  printf("\nFull string: %s\n", str2);
  while (sscanf(ptr2, "%14[^:]%n", field2, &n2) == 1) {
    printf("%d field = %s (%d byte)\n", i, field2, n2);
    ptr2 += n2;
    if (*ptr2 != ':')
      break;
    ++ptr2, i++;
  }
  free(field2);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x2c,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x35,%edx
call   1050 <memcpy@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0xa0(%rbp)
movl   $0x1,-0x58(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe87(%rip),%rsi
lea    -0x54(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1248 <main+0xf8>
mov    -0x58(%rbp),%esi
lea    -0x50(%rbp),%rdx
mov    -0x54(%rbp),%ecx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x54(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     122e <main+0xde>
jmp    1248 <main+0xf8>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11cf <main+0x7f>
movl   $0x1,-0x58(%rbp)
lea    -0x90(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
lea    0xe21(%rip),%rsi
lea    -0xa4(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    12fe <main+0x1ae>
mov    -0x58(%rbp),%esi
mov    -0xa0(%rbp),%rdx
mov    -0xa4(%rbp),%ecx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xa4(%rbp),%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     12de <main+0x18e>
jmp    12fe <main+0x1ae>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1264 <main+0x114>
mov    -0xa0(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movups 0xec4(%rip),%xmm0
movups %xmm0,0x8c(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x68737a2f6e6962,%rax
mov    %rax,0x5d(%rsp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xec7(%rip),%rdi
lea    0x70(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8d(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1252 <main+0x112>
mov    $0x1,%ebp
lea    0x10(%rsp),%r12
lea    0xe65(%rip),%r13
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    0xc(%rsp),%ecx
lea    0xe54(%rip),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
cmpb   $0x3b,(%rbx,%rax,1)
jne    1252 <main+0x112>
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1210 <main+0xd0>
lea    0xe2f(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2b(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    12de <main+0x19e>
mov    $0x1,%ebp
lea    0xddf(%rip),%r15
lea    0xe03(%rip),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x8(%rsp),%rax
cmpb   $0x3a,(%rbx,%rax,1)
jne    12de <main+0x19e>
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     12a0 <main+0x160>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [44 x i8] c"1982/08/12 21:30:37;data1;data2;data3;data4\00"
@__const.main.str2 = [53 x i8] c"b3h3m0th:x:1000:1000:,,,:/home/b3h3m0th:/usr/bin/zsh\00"
@.str = [17 x i8] c"Full string: %s\0A\00"
@.str.1 = [10 x i8] c"%19[^;]%n\00"
@.str.2 = [25 x i8] c"%d field = %s (%d byte)\0A\00"
@.str.3 = [18 x i8] c"\0AFull string: %s\0A\00"
@.str.4 = [10 x i8] c"%14[^:]%n\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [44 x i8]
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [53 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [44 x i8]* %2 to i8*
%12 = getelementptr inbounds [44 x i8], [44 x i8]* %2, i64 0, i64 0
store i8* %12, i8** %3
%13 = bitcast [53 x i8]* %7 to i8*
%14 = getelementptr inbounds [53 x i8], [53 x i8]* %7, i64 0, i64 0
store i8* %14, i8** %8
%15 = call i64 @malloc(i32 4)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
store i32 1, i32* %6
%17 = getelementptr inbounds [44 x i8], [44 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %38, %0
%20 = load i8*, i8** %3
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%22 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32* %5)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %43
24: ; preds = %19
%25 = load i32, i32* %6
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %5
%30 = load i8*, i8** %3
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %3
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 59
br i1 %36, label %37, label %38
37: ; preds = %24
br label %43
38: ; preds = %24
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %19
43: ; preds = %37, %19
store i32 1, i32* %6
%44 = getelementptr inbounds [53 x i8], [53 x i8]* %7, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %65, %43
%47 = load i8*, i8** %8
%48 = load i8*, i8** %9
%49 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32* %10)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %70
51: ; preds = %46
%52 = load i32, i32* %6
%53 = load i8*, i8** %9
%54 = load i32, i32* %10
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %52, i8* %53, i32 %54)
%56 = load i32, i32* %10
%57 = load i8*, i8** %8
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8* %59, i8** %8
%60 = load i8*, i8** %8
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 58
br i1 %63, label %64, label %65
64: ; preds = %51
br label %70
65: ; preds = %51
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %46
70: ; preds = %64, %46
%71 = load i8*, i8** %9
%72 = call i32 @free(i8* %71)
%73 = load i32, i32* @EXIT_SUCCESS
ret i32 %73
}

LLVM IR (-O2):
@__const.main.str = [44 x i8] c"1982/08/12 21:30:37;data1;data2;data3;data4\00"
@__const.main.str2 = [53 x i8] c"b3h3m0th:x:1000:1000:,,,:/home/b3h3m0th:/usr/bin/zsh\00"
@.str = [17 x i8] c"Full string: %s\0A\00"
@.str.1 = [10 x i8] c"%19[^;]%n\00"
@.str.2 = [25 x i8] c"%d field = %s (%d byte)\0A\00"
@.str.3 = [18 x i8] c"\0AFull string: %s\0A\00"
@.str.4 = [10 x i8] c"%14[^:]%n\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [44 x i8]
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca [53 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [44 x i8], [44 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [53 x i8], [53 x i8]* %4, i64 0, i64 0
%10 = tail call i64 @malloc(i32 4)
%11 = inttoptr i64 %10 to i8*
%12 = bitcast i32* %5 to i8*
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %6)
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32* %3)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %31
16: ; preds = %0, %26
%17 = phi i8* [ %27, %26 ], [ %6, %0 ]
%18 = phi i32 [ %28, %26 ], [ 1, %0 ]
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %7, i32 %19)
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 59
br i1 %25, label %26, label %31
26: ; preds = %16
%27 = getelementptr inbounds i8, i8* %23, i64 1
%28 = add nuw nsw i32 %18, 1
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32* %3)
%30 = icmp eq i32 %29, 1
br i1 %30, label %16, label %31
31: ; preds = %26, %16, %0
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%33 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11, i32* %5)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %50
35: ; preds = %31, %45
%36 = phi i8* [ %46, %45 ], [ %9, %31 ]
%37 = phi i32 [ %47, %45 ], [ 1, %31 ]
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* %11, i32 %38)
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %36, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 58
br i1 %44, label %45, label %50
45: ; preds = %35
%46 = getelementptr inbounds i8, i8* %42, i64 1
%47 = add nuw nsw i32 %37, 1
%48 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11, i32* %5)
%49 = icmp eq i32 %48, 1
br i1 %49, label %35, label %50
50: ; preds = %45, %35, %31
%51 = call i32 @free(i8* %11)
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}