#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 */
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ fmtsub(char *, int, char *, char const ***);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  char buf2[32];
  char buf[64];
  char *pattern = argv[1];
  char proba[64];
  strcpy(proba, "PROBA");
  const char *args[][2] = {{"%n", NULL},        {"", "URES_STRING"},
                           {"%v", "0.9.6-rc2"}, {"%a", "Jekusa Poromeck"},
                           {"%p", proba},       {"Windows", "Linux"},
                           {"\\%", "%"},        {0}};
  if (fmtsub(buf, sizeof(buf), pattern, args)) {
    printf("fmtsub() hibaval tert vissza!\n");
  }
  printf("%d s %s s\n", (int)strlen(buf), buf);
  strncpy(buf2, buf, sizeof(buf2) - 1);
  printf("%d s %s s\n", (int)strlen(buf2), buf2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x140(%rbp),%rcx
lea    0xe70(%rip),%rax
mov    %rax,-0x140(%rbp)
movq   $0x0,-0x138(%rbp)
add    $0x10,%rcx
lea    0xeb4(%rip),%rax
mov    %rax,-0x130(%rbp)
lea    0xe48(%rip),%rax
mov    %rax,-0x128(%rbp)
add    $0x10,%rcx
lea    0xe42(%rip),%rax
mov    %rax,-0x120(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x118(%rbp)
add    $0x10,%rcx
lea    0xe2f(%rip),%rax
mov    %rax,-0x110(%rbp)
lea    0xe24(%rip),%rax
mov    %rax,-0x108(%rbp)
add    $0x10,%rcx
lea    0xe22(%rip),%rax
mov    %rax,-0x100(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
add    $0x10,%rcx
lea    0xe05(%rip),%rax
mov    %rax,-0xf0(%rbp)
lea    0xdff(%rip),%rax
mov    %rax,-0xe8(%rbp)
add    $0x10,%rcx
lea    0xdf3(%rip),%rax
mov    %rax,-0xe0(%rbp)
lea    0xde6(%rip),%rax
mov    %rax,-0xd8(%rbp)
add    $0x10,%rcx
movq   $0x0,-0xd0(%rbp)
mov    %rcx,%rax
add    $0x8,%rax
add    $0x10,%rcx
mov    %rcx,-0x150(%rbp)
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rax
mov    -0x150(%rbp),%rcx
movq   $0x0,(%rax)
add    $0x8,%rax
mov    %rax,-0x158(%rbp)
cmp    %rcx,%rax
mov    %rax,-0x148(%rbp)
jne    1290 <main+0x140>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
lea    -0x140(%rbp),%rcx
mov    $0x40,%esi
call   1050 <fmtsub@plt>
cmp    $0x0,%rax
je     12f1 <main+0x1a1>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    -0x70(%rbp),%rdx
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    0x8(%rsi),%r14
lea    0xe89(%rip),%rsi
lea    0xe0(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe78(%rip),%rax
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xeb1(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe5b(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe5b(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe52(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe50(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe47(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe4b(%rip),%rax
mov    %rax,0x40(%rsp)
mov    %rbx,0x48(%rsp)
lea    0xe3d(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xe39(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xe33(%rip),%rax
mov    %rax,0x60(%rsp)
lea    0xe28(%rip),%rax
mov    %rax,0x68(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
lea    0x80(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x40,%esi
mov    %r14,%rdx
call   1060 <fmtsub@plt>
test   %rax,%rax
je     1255 <main+0xf5>
lea    0xe04(%rip),%rdi
call   1050 <puts@plt>
lea    0x80(%rsp),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0xddd(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"PROBA\00"
@.str.1 = [3 x i8] c"%n\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"URES_STRING\00"
@.str.4 = [3 x i8] c"%v\00"
@.str.5 = [10 x i8] c"0.9.6-rc2\00"
@.str.6 = [3 x i8] c"%a\00"
@.str.7 = [16 x i8] c"Jekusa Poromeck\00"
@.str.8 = [3 x i8] c"%p\00"
@.str.9 = [8 x i8] c"Windows\00"
@.str.10 = [6 x i8] c"Linux\00"
@.str.11 = [3 x i8] c"\\%\00"
@.str.12 = [2 x i8] c"%\00"
@.str.13 = [31 x i8] c"fmtsub() hibaval tert vissza!\0A\00"
@.str.14 = [11 x i8] c"%d s %s s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca [64 x i8]
%8 = alloca i8*
%9 = alloca [64 x i8]
%10 = alloca [8 x [2 x i8*]]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %8
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %10, i64 0, i64 0
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %16, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* null, i8** %18
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %16, i64 1
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %19, i64 0, i64 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds i8*, i8** %20, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %19, i64 1
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %22, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %22, i64 1
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %25, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds i8*, i8** %26, i64 1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %25, i64 1
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %28, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %29
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
store i8* %31, i8** %30
%32 = getelementptr inbounds [2 x i8*], [2 x i8*]* %28, i64 1
%33 = getelementptr inbounds [2 x i8*], [2 x i8*]* %32, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8** %33
%34 = getelementptr inbounds i8*, i8** %33, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8** %34
%35 = getelementptr inbounds [2 x i8*], [2 x i8*]* %32, i64 1
%36 = getelementptr inbounds [2 x i8*], [2 x i8*]* %35, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds i8*, i8** %36, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i8** %37
%38 = getelementptr inbounds [2 x i8*], [2 x i8*]* %35, i64 1
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %38, i64 0, i64 0
store i8* null, i8** %39
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = getelementptr inbounds i8*, i8** %39, i64 2
br label %42
42: ; preds = %42, %2
%43 = phi i8** [ %40, %2 ], [ %44, %42 ]
store i8* null, i8** %43
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = icmp eq i8** %44, %41
br i1 %45, label %46, label %42
46: ; preds = %42
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%48 = load i8*, i8** %8
%49 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %10, i64 0, i64 0
%50 = bitcast [2 x i8*]* %49 to i8***
%51 = call i64 @fmtsub(i8* %47, i32 64, i8* %48, i8*** %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
br label %55
55: ; preds = %53, %46
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%57 = call i64 @strlen(i8* %56)
%58 = trunc i64 %57 to i32
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %58, i8* %59)
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%63 = call i32 @strncpy(i8* %61, i8* %62, i32 31)
%64 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%65 = call i64 @strlen(i8* %64)
%66 = trunc i64 %65 to i32
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %66, i8* %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"PROBA\00"
@.str.1 = [3 x i8] c"%n\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"URES_STRING\00"
@.str.4 = [3 x i8] c"%v\00"
@.str.5 = [10 x i8] c"0.9.6-rc2\00"
@.str.6 = [3 x i8] c"%a\00"
@.str.7 = [16 x i8] c"Jekusa Poromeck\00"
@.str.8 = [3 x i8] c"%p\00"
@.str.9 = [8 x i8] c"Windows\00"
@.str.10 = [6 x i8] c"Linux\00"
@.str.11 = [3 x i8] c"\\%\00"
@.str.12 = [2 x i8] c"%\00"
@.str.14 = [11 x i8] c"%d s %s s\0A\00"
@str = [30 x i8] c"fmtsub() hibaval tert vissza!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca [8 x [2 x i8*]]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = bitcast [8 x [2 x i8*]]* %6 to i8*
%14 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 0, i64 1
store i8* null, i8** %15
%16 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 1, i64 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 1, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 2, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 2, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 3, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 3, i64 1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 4, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 4, i64 1
store i8* %11, i8** %23
%24 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 5, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 5, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8** %25
%26 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 6, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 6, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds [8 x [2 x i8*]], [8 x [2 x i8*]]* %6, i64 0, i64 7, i64 0
%29 = bitcast [8 x [2 x i8*]]* %6 to i8***
%30 = bitcast i8** %28 to i8*
%31 = call i64 @fmtsub(i8* %8, i32 64, i8* %10, i8*** %29)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %2
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %2
%36 = call i64 @strlen(i8* %8)
%37 = trunc i64 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %37, i8* %8)
%39 = call i32 @strncpy(i8* %7, i8* %8, i32 31)
%40 = call i64 @strlen(i8* %7)
%41 = trunc i64 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %41, i8* %7)
ret i32 0
}