#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*/ iconv;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ puts(char *);
scalar_t__ read_strings(int /*<<< orphan*/ *, char *, int, char **, char **);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ write_po(int /*<<< orphan*/ *, char *, char *);
int main(int argc, char *argv[]) {
  FILE *strings, *po;
  char iconv[1024], buffer[8192], *id, *str;
  int count;
  if (argc != 3) {
    puts("Usage: strings2po filename.strings filename.po");
    return (1);
  }
  snprintf(iconv, sizeof(iconv), "iconv -f utf-16 -t utf-8 '%s'", argv[1]);
  if ((strings = popen(iconv, "r")) == NULL) {
    perror(argv[1]);
    return (1);
  }
  if ((po = fopen(argv[2], "w")) == NULL) {
    perror(argv[2]);
    pclose(strings);
    return (1);
  }
  count = 0;
  while (read_strings(strings, buffer, sizeof(buffer), &id, &str)) {
    count++;
    write_po(po, "msgid", id);
    write_po(po, "msgstr", str);
  }
  pclose(strings);
  fclose(po);
  printf("%s: %d messages.\n", argv[2], count);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11db <main+0x3b>
lea    0xe36(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x185>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x400,%esi
lea    0xe39(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1235 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe09(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1279 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1080 <pclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1325 <main+0x185>
movl   $0x0,-0x2434(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2420(%rbp),%rsi
mov    $0x2000,%edx
lea    -0x2428(%rbp),%rcx
lea    -0x2430(%rbp),%r8
call   1040 <read_strings@plt>
cmp    $0x0,%rax
je     12f2 <main+0x152>
mov    -0x2434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2434(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2428(%rbp),%rdx
lea    0xd7e(%rip),%rsi
call   1030 <write_po@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2430(%rbp),%rdx
lea    0xd6d(%rip),%rsi
call   1030 <write_po@plt>
jmp    1283 <main+0xe3>
mov    -0x18(%rbp),%rdi
call   1080 <pclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x2434(%rbp),%edx
lea    0xd43(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2428,%rsp
cmp    $0x3,%edi
jne    12d1 <main+0x131>
mov    %rsi,%rbx
mov    0x8(%rsi),%rcx
lea    0xe67(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
call   1090 <snprintf@plt>
lea    0xe79(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <popen@plt>
test   %rax,%rax
je     12f4 <main+0x154>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12ff <main+0x15f>
mov    %rax,%rbp
mov    %rbx,0x18(%rsp)
lea    0x420(%rsp),%rsi
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r12,%rdi
mov    $0x2000,%edx
call   1040 <read_strings@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     12a6 <main+0x106>
xor    %ebx,%ebx
lea    0x420(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
mov    0x10(%rsp),%rdx
mov    %rbp,%rdi
lea    0xddd(%rip),%rsi
call   1030 <write_po@plt>
mov    0x8(%rsp),%rdx
mov    %rbp,%rdi
lea    0xdcf(%rip),%rsi
call   1030 <write_po@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x2000,%edx
mov    %r13,%rcx
mov    %r14,%r8
call   1040 <read_strings@plt>
test   %rax,%rax
jne    1260 <main+0xc0>
mov    %r12,%rdi
call   1080 <pclose@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x18(%rsp),%rax
mov    0x10(%rax),%rsi
lea    0xd96(%rip),%rdi
mov    %ebx,%edx
call   1070 <printf@plt>
xor    %eax,%eax
jmp    12e2 <main+0x142>
lea    0xd28(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x2428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   10c0 <perror@plt>
jmp    12dd <main+0x13d>
mov    0x10(%rbx),%rdi
call   10c0 <perror@plt>
mov    %r12,%rdi
call   1080 <pclose@plt>
jmp    12dd <main+0x13d>

LLVM IR (-O0):
@.str = [47 x i8] c"Usage: strings2po filename.strings filename.po\00"
@.str.1 = [30 x i8] c"iconv -f utf-16 -t utf-8 '%s'\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"msgid\00"
@.str.5 = [7 x i8] c"msgstr\00"
@.str.6 = [18 x i8] c"%s: %d messages.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca [8192 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %69
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @snprintf(i8* %18, i32 1024, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @perror(i8* %29)
store i32 1, i32* %3
br label %69
31: ; preds = %17
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @perror(i8* %40)
%42 = load i32*, i32** %6
%43 = call i32 @pclose(i32* %42)
store i32 1, i32* %3
br label %69
44: ; preds = %31
store i32 0, i32* %12
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %6
%47 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%48 = call i64 @read_strings(i32* %46, i8* %47, i32 8192, i8** %10, i8** %11)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %45
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
%53 = load i32*, i32** %7
%54 = load i8*, i8** %10
%55 = call i32 @write_po(i32* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = load i32*, i32** %7
%57 = load i8*, i8** %11
%58 = call i32 @write_po(i32* %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %45
59: ; preds = %45
%60 = load i32*, i32** %6
%61 = call i32 @pclose(i32* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = load i32, i32* %12
%68 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %66, i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %59, %37, %26, %15
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [47 x i8] c"Usage: strings2po filename.strings filename.po\00"
@.str.1 = [30 x i8] c"iconv -f utf-16 -t utf-8 '%s'\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"msgid\00"
@.str.5 = [7 x i8] c"msgstr\00"
@.str.6 = [18 x i8] c"%s: %d messages.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [8192 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%9 = bitcast i8** %5 to i8*
%10 = bitcast i8** %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %50
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %15
%22 = call i32 @perror(i8* %21)
br label %50
23: ; preds = %14
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = call i64 @read_strings(i32* %18, i8* %8, i32 8192, i8** %5, i8** %6)
%30 = icmp eq i64 %29, 0
br i1 %30, label %44, label %35
31: ; preds = %23
%32 = load i8*, i8** %24
%33 = call i32 @perror(i8* %32)
%34 = call i32 @pclose(i32* %18)
br label %50
35: ; preds = %28, %35
%36 = phi i32 [ %37, %35 ], [ 0, %28 ]
%37 = add nuw nsw i32 %36, 1
%38 = load i8*, i8** %5
%39 = call i32 @write_po(i32* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %6
%41 = call i32 @write_po(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = call i64 @read_strings(i32* %18, i8* %8, i32 8192, i8** %5, i8** %6)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %35
44: ; preds = %35, %28
%45 = phi i32 [ 0, %28 ], [ %37, %35 ]
%46 = call i32 @pclose(i32* %18)
%47 = call i32 @fclose(i32* %26)
%48 = load i8*, i8** %24
%49 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %48, i32 %45)
br label %50
50: ; preds = %44, %31, %20, %12
%51 = phi i32 [ 1, %12 ], [ 1, %20 ], [ 1, %31 ], [ 0, %44 ]
ret i32 %51
}