#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 */
double atof(char *);
char *index(char *, char);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void g_to_ugs(char *c0, char *c1, int digflag) {
  int i, n;
  char *p;
  *c1 = '\0';
  n = strlen(c0);
  p = index(c0, 'e');
  if (p == (char *)0) {
    strcpy(c1, c0);
    return;
  }
  *p = '\0';
  if (!digflag && atof(c0) == 0.0) {
    strcpy(c1, "0");
    return;
  }
  if (!digflag && atof(c0) == 1.0) {
  } else if (!digflag && atof(c0) == -1.0) {
    c1[0] = '-';
    c1[1] = '\0';
  } else {
    strcpy(c1, c0);
    n = strlen(c1);
    c1[n] = 0x82;
    c1[n + 1] = '\0';
  }
  p++;
  strcat(c1, "10");
  n = strlen(c1);
  c1[n] = 0x90;
  c1[n + 1] = '\0';
  sscanf(p, "%d", &i);
  sprintf(p, "%d", i);
  strcat(c1, p);
  return;
}


x86 assembly (clang, -O0):
<g_to_ugs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x65,%esi
call   1060 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c5 <g_to_ugs+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    132a <g_to_ugs+0x1ba>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
jne    1207 <g_to_ugs+0x97>
mov    -0x8(%rbp),%rdi
call   1040 <atof@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1207 <g_to_ugs+0x97>
jp     1207 <g_to_ugs+0x97>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1030 <strcpy@plt>
jmp    132a <g_to_ugs+0x1ba>
cmpl   $0x0,-0x14(%rbp)
jne    1237 <g_to_ugs+0xc7>
mov    -0x8(%rbp),%rdi
call   1040 <atof@plt>
movsd  0xdde(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1237 <g_to_ugs+0xc7>
jp     1237 <g_to_ugs+0xc7>
jmp    12b1 <g_to_ugs+0x141>
cmpl   $0x0,-0x14(%rbp)
jne    1276 <g_to_ugs+0x106>
mov    -0x8(%rbp),%rdi
call   1040 <atof@plt>
movsd  0xdb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1276 <g_to_ugs+0x106>
jp     1276 <g_to_ugs+0x106>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    12ac <g_to_ugs+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x82,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12b1 <g_to_ugs+0x141>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x90,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
lea    0xd12(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xcfb(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_to_ugs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
movb   $0x0,(%rsi)
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x65,%esi
call   1060 <index@plt>
test   %rax,%rax
je     122f <g_to_ugs+0xbf>
mov    %rax,%r14
movb   $0x0,(%rax)
test   %ebp,%ebp
je     1237 <g_to_ugs+0xc7>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x82,(%r15,%rax,1)
add    $0x1,%eax
cltq
movb   $0x0,(%r15,%rax,1)
add    $0x1,%r14
lea    0xe36(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movw   $0x90,(%r15,%rax,1)
lea    0xe19(%rip),%rbx
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <sscanf@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %rbx,%rsi
jmp    1255 <g_to_ugs+0xe5>
mov    %rbx,%rdi
call   1040 <atof@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1264 <g_to_ugs+0xf4>
jp     1264 <g_to_ugs+0xf4>
lea    0xdbf(%rip),%rsi
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>
ucomisd 0xd94(%rip),%xmm0
jne    1274 <g_to_ugs+0x104>
jnp    11cf <g_to_ugs+0x5f>
ucomisd 0xd8c(%rip),%xmm0
jne    11ab <g_to_ugs+0x3b>
jp     11ab <g_to_ugs+0x3b>
movb   $0x2d,(%r15)
mov    $0x1,%eax
jmp    11ca <g_to_ugs+0x5a>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [3 x i8] c"10\00"
@.str.2 = [3 x i8] c"%d\00"
define void @g_to_ugs(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8 0, i8* %10
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i8*, i8** %4
%14 = call i8* @index(i8* %13, i8 signext 101)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %18, i8* %19)
br label %92
21: ; preds = %3
%22 = load i8*, i8** %9
store i8 0, i8* %22
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call double @atof(i8* %26)
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %92
32: ; preds = %25, %21
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = call double @atof(i8* %36)
%38 = fcmp oeq double %37, 1.000000e+00
br i1 %38, label %39, label %40
39: ; preds = %35
br label %68
40: ; preds = %35, %32
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %40
%44 = load i8*, i8** %4
%45 = call double @atof(i8* %44)
%46 = fcmp oeq double %45, -1.000000e+00
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
store i8 45, i8* %49
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8 0, i8* %51
br label %67
52: ; preds = %43, %40
%53 = load i8*, i8** %5
%54 = load i8*, i8** %4
%55 = call i32 @strcpy(i8* %53, i8* %54)
%56 = load i8*, i8** %5
%57 = call i32 @strlen(i8* %56)
store i32 %57, i32* %8
%58 = load i8*, i8** %5
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 -126, i8* %61
%62 = load i8*, i8** %5
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %52, %47
br label %68
68: ; preds = %67, %39
%69 = load i8*, i8** %9
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %9
%71 = load i8*, i8** %5
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%73 = load i8*, i8** %5
%74 = call i32 @strlen(i8* %73)
store i32 %74, i32* %8
%75 = load i8*, i8** %5
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 -112, i8* %78
%79 = load i8*, i8** %5
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
store i8 0, i8* %83
%84 = load i8*, i8** %9
%85 = call i32 @sscanf(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%86 = load i8*, i8** %9
%87 = load i32, i32* %7
%88 = call i32 @sprintf(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %87)
%89 = load i8*, i8** %5
%90 = load i8*, i8** %9
%91 = call i32 @strcat(i8* %89, i8* %90)
br label %92
92: ; preds = %68, %29, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [3 x i8] c"10\00"
@.str.2 = [3 x i8] c"%d\00"
define void @g_to_ugs(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i8 0, i8* %1
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* @index(i8* %0, i8 signext 101)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %46
11: ; preds = %3
store i8 0, i8* %7
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %23
13: ; preds = %11
%14 = tail call double @atof(i8* %0)
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %46
18: ; preds = %13
%19 = fcmp oeq double %14, 1.000000e+00
br i1 %19, label %33, label %20
20: ; preds = %18
%21 = fcmp oeq double %14, -1.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %20
store i8 45, i8* %1
br label %30
23: ; preds = %11, %20
%24 = tail call i32 @strcpy(i8* %1, i8* %0)
%25 = tail call i32 @strlen(i8* %1)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 -126, i8* %27
%28 = add nsw i32 %25, 1
%29 = sext i32 %28 to i64
br label %30
30: ; preds = %23, %22
%31 = phi i64 [ 1, %22 ], [ %29, %23 ]
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %30, %18
%34 = getelementptr inbounds i8, i8* %7, i64 1
%35 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%36 = tail call i32 @strlen(i8* %1)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %1, i64 %37
store i8 -112, i8* %38
%39 = add nsw i32 %36, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %1, i64 %40
store i8 0, i8* %41
%42 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%43 = load i32, i32* %4
%44 = call i32 @sprintf(i8* %34, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = call i32 @strcat(i8* %1, i8* %34)
br label %46
46: ; preds = %33, %16, %9
ret void
}