#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 /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *strtok(char *, char *);
char tolower(char);
char toupper(char);
void zamijeni(char *recenica) {
  int i;
  char *prva, *druga, *ostatak, *ispis;
  char zadnjiznak;
  char delimit[] = " ?!.";
  ispis = (char *)malloc((strlen(recenica) + 1) * sizeof(char));
  for (i = 0; i < strlen(ispis); i++)
    *(ispis + i) = '\0';
  if (strstr(recenica, " ") == NULL)
    exit(0);
  zadnjiznak = *(recenica + (strlen(recenica) - 1));
  prva = strtok(recenica, delimit);
  druga = strtok(NULL, delimit);
  ostatak = strtok(NULL, "\0");
  *druga = toupper(*druga);
  *prva = tolower(*prva);
  if (ostatak != NULL) {
    strcat(ispis, druga);
    strcat(ispis, " ");
    strcat(ispis, prva);
    strcat(ispis, " ");
    strcat(ispis, ostatak);
  } else {
    strcat(ispis, druga);
    strcat(ispis, " ");
    strcat(ispis, prva);
    strcat(ispis, &zadnjiznak);
  }
  printf("%s\n", ispis);
  free(recenica);
  free(ispis);
}


x86 assembly (clang, -O0):
<zamijeni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe4e(%rip),%eax
mov    %eax,-0x36(%rbp)
mov    0xe49(%rip),%al
mov    %al,-0x32(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    1218 <zamijeni+0x78>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <zamijeni+0x42>
mov    -0x8(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
jne    1239 <zamijeni+0x99>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x36(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x18(%rbp)
lea    -0x36(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd82(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1070 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1311 <zamijeni+0x171>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xd28(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xd0b(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <strcat@plt>
jmp    1348 <zamijeni+0x1a8>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xcdc(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    -0x31(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rsi
lea    0xcb4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zamijeni>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movb   $0x0,0x14(%rsp)
movl   $0x2e213f20,0x10(%rsp)
2e
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11f8 <zamijeni+0x58>
xor    %ebx,%ebx
nopl   0x0(%rax)
movb   $0x0,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11e0 <zamijeni+0x40>
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     12ea <zamijeni+0x14a>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
mov    -0x1(%rax,%r14,1),%al
mov    %al,0xf(%rsp)
lea    0x10(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %r15,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r13
lea    0xdc3(%rip),%rsi
xor    %edi,%edi
call   10a0 <strtok@plt>
mov    %rax,%r15
movsbl 0x0(%r13),%edi
call   1040 <toupper@plt>
mov    %al,0x0(%r13)
movsbl (%r12),%edi
call   1080 <tolower@plt>
mov    %al,(%r12)
mov    %rbp,%rdi
mov    %r13,%rsi
call   10b0 <strcat@plt>
lea    0xd85(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
test   %r15,%r15
je     12af <zamijeni+0x10f>
lea    0xd66(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
jmp    12b7 <zamijeni+0x117>
lea    0xf(%rsp),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
lea    0xd44(%rip),%rdi
mov    %rbp,%rsi
call   1070 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.zamijeni.delimit = [5 x i8] c" ?!.\00"
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [4 x i8] c"%s\0A\00"
define void @zamijeni(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca [5 x i8]
store i8* %0, i8** %2
%10 = bitcast [5 x i8]* %9 to i8*
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %7
store i32 0, i32* %3
br label %19
19: ; preds = %29, %1
%20 = load i32, i32* %3
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %24
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %19
32: ; preds = %19
%33 = load i8*, i8** %2
%34 = call i32* @strstr(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %32
%39 = load i8*, i8** %2
%40 = load i8*, i8** %2
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
%45 = load i8, i8* %44
store i8 %45, i8* %8
%46 = load i8*, i8** %2
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%48 = call i8* @strtok(i8* %46, i8* %47)
store i8* %48, i8** %4
%49 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%50 = call i8* @strtok(i8* null, i8* %49)
store i8* %50, i8** %5
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %51, i8** %6
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = call signext i8 @toupper(i8 signext %53)
%55 = load i8*, i8** %5
store i8 %54, i8* %55
%56 = load i8*, i8** %4
%57 = load i8, i8* %56
%58 = call signext i8 @tolower(i8 signext %57)
%59 = load i8*, i8** %4
store i8 %58, i8* %59
%60 = load i8*, i8** %6
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %76
62: ; preds = %38
%63 = load i8*, i8** %7
%64 = load i8*, i8** %5
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i8*, i8** %7
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%68 = load i8*, i8** %7
%69 = load i8*, i8** %4
%70 = call i32 @strcat(i8* %68, i8* %69)
%71 = load i8*, i8** %7
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%73 = load i8*, i8** %7
%74 = load i8*, i8** %6
%75 = call i32 @strcat(i8* %73, i8* %74)
br label %87
76: ; preds = %38
%77 = load i8*, i8** %7
%78 = load i8*, i8** %5
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = load i8*, i8** %7
%81 = call i32 @strcat(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%82 = load i8*, i8** %7
%83 = load i8*, i8** %4
%84 = call i32 @strcat(i8* %82, i8* %83)
%85 = load i8*, i8** %7
%86 = call i32 @strcat(i8* %85, i8* %8)
br label %87
87: ; preds = %76, %62
%88 = load i8*, i8** %7
%89 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %2
%91 = call i32 @free(i8* %90)
%92 = load i8*, i8** %7
%93 = call i32 @free(i8* %92)
ret void
}

LLVM IR (-O2):
@__const.zamijeni.delimit = [5 x i8] c" ?!.\00"
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [4 x i8] c"%s\0A\00"
define void @zamijeni(i8* %0) {
%2 = alloca i8
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1, %11
%12 = phi i64 [ %14, %11 ], [ 0, %1 ]
%13 = getelementptr inbounds i8, i8* %8, i64 %12
store i8 0, i8* %13
%14 = add nuw nsw i64 %12, 1
%15 = tail call i32 @strlen(i8* %8)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %11, label %18
18: ; preds = %11, %1
%19 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @exit(i32 0)
unreachable
23: ; preds = %18
%24 = tail call i32 @strlen(i8* %0)
%25 = add nsw i32 %24, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %2
%29 = call i8* @strtok(i8* %0, i8* %4)
%30 = call i8* @strtok(i8* null, i8* %4)
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8, i8* %30
%33 = tail call signext i8 @toupper(i8 signext %32)
store i8 %33, i8* %30
%34 = load i8, i8* %29
%35 = tail call signext i8 @tolower(i8 signext %34)
store i8 %35, i8* %29
%36 = icmp eq i8* %31, null
%37 = tail call i32 @strcat(i8* %8, i8* %30)
%38 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @strcat(i8* %8, i8* %29)
br i1 %36, label %43, label %40
40: ; preds = %23
%41 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = tail call i32 @strcat(i8* %8, i8* %31)
br label %45
43: ; preds = %23
%44 = call i32 @strcat(i8* %8, i8* %2)
br label %45
45: ; preds = %43, %40
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%47 = call i32 @free(i8* %0)
%48 = call i32 @free(i8* %8)
ret void
}